From 15935ec10977aa51cf8990c6c15d853430944bd4 Mon Sep 17 00:00:00 2001 From: Akinwale Ariwodola Date: Wed, 28 Oct 2020 15:23:28 +0100 Subject: [PATCH 1/8] fix CQ load when fetching more claims for a publishher --- src/Controller/MainController.php | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/Controller/MainController.php b/src/Controller/MainController.php index 3927e99..15a6515 100644 --- a/src/Controller/MainController.php +++ b/src/Controller/MainController.php @@ -219,7 +219,15 @@ class MainController extends AppController { $moreClaims = []; if (isset($claim->publisher) || $claim->claim_type == 1) { // find more claims for the publisher - $moreClaims = $this->Claims->find()->select($this->Claims)->select(['publisher' => 'C.name'])->leftJoin(['C' => 'claim'], ['C.claim_id = Claims.publisher_id'])->where(['Claims.claim_type' => 1, 'Claims.id <>' => $claim->id, 'Claims.publisher_id' => isset($claim->publisher) ? $claim->publisher_id : $claim->claim_id])->limit(9)->order(['Claims.fee' => 'DESC', 'RAND()' => 'DESC'])->toArray(); + $moreClaimsQuery = $this->Claims->find()->select([ + 'claim_id', 'bid_state', 'price', 'fee', 'fee_currency', 'is_nsfw', 'claim_type', + 'name', 'title', 'description', 'content_type', 'language', 'author', 'license', + 'content_type' + ])->select(['publisher' => 'C.name'])->leftJoin(['C' => 'claim'], ['C.claim_id = Claims.publisher_id'])->where(['Claims.claim_type' => 1, 'Claims.id <>' => $claim->id, 'Claims.publisher_id' => isset($claim->publisher) ? $claim->publisher_id : $claim->claim_id])->limit(9); + if ($id !== 'f2cf43b86b9d70175dc22dbb9ff7806241d90780') { // prevent ORDER BY for this particular claim + $moreClaimsQuery = $moreClaimsQuery->order(['Claims.fee' => 'DESC', 'RAND()' => 'DESC']); + } + $moreClaims = $moreClaimsQuery->toArray(); for ($i = 0; $i < count($moreClaims); $i++) { if ($canConvert && $moreClaims[$i]->fee > 0 && $moreClaims[$i]->fee_currency == 'USD') { $moreClaims[$i]->price = $moreClaims[$i]->fee / $priceInfo->price; -- 2.45.2 From b9fe194dc8b4139f599a25e0f50114e877d8e493 Mon Sep 17 00:00:00 2001 From: Akinwale Ariwodola Date: Wed, 28 Oct 2020 15:37:39 +0100 Subject: [PATCH 2/8] check publisher claim_id --- src/Controller/MainController.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Controller/MainController.php b/src/Controller/MainController.php index 15a6515..614f710 100644 --- a/src/Controller/MainController.php +++ b/src/Controller/MainController.php @@ -224,7 +224,7 @@ class MainController extends AppController { 'name', 'title', 'description', 'content_type', 'language', 'author', 'license', 'content_type' ])->select(['publisher' => 'C.name'])->leftJoin(['C' => 'claim'], ['C.claim_id = Claims.publisher_id'])->where(['Claims.claim_type' => 1, 'Claims.id <>' => $claim->id, 'Claims.publisher_id' => isset($claim->publisher) ? $claim->publisher_id : $claim->claim_id])->limit(9); - if ($id !== 'f2cf43b86b9d70175dc22dbb9ff7806241d90780') { // prevent ORDER BY for this particular claim + if ($claim->publisher->claim_id !== 'f2cf43b86b9d70175dc22dbb9ff7806241d90780') { // prevent ORDER BY for this particular claim $moreClaimsQuery = $moreClaimsQuery->order(['Claims.fee' => 'DESC', 'RAND()' => 'DESC']); } $moreClaims = $moreClaimsQuery->toArray(); -- 2.45.2 From aad314491b7004ac5b5684431a6586e57a22b5d7 Mon Sep 17 00:00:00 2001 From: Akinwale Ariwodola Date: Wed, 28 Oct 2020 15:41:17 +0100 Subject: [PATCH 3/8] additional check for claim publisher --- src/Controller/MainController.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Controller/MainController.php b/src/Controller/MainController.php index 614f710..6db2f03 100644 --- a/src/Controller/MainController.php +++ b/src/Controller/MainController.php @@ -224,7 +224,7 @@ class MainController extends AppController { 'name', 'title', 'description', 'content_type', 'language', 'author', 'license', 'content_type' ])->select(['publisher' => 'C.name'])->leftJoin(['C' => 'claim'], ['C.claim_id = Claims.publisher_id'])->where(['Claims.claim_type' => 1, 'Claims.id <>' => $claim->id, 'Claims.publisher_id' => isset($claim->publisher) ? $claim->publisher_id : $claim->claim_id])->limit(9); - if ($claim->publisher->claim_id !== 'f2cf43b86b9d70175dc22dbb9ff7806241d90780') { // prevent ORDER BY for this particular claim + if (isset($claim->publisher) && $claim->publisher->claim_id !== 'f2cf43b86b9d70175dc22dbb9ff7806241d90780') { // prevent ORDER BY for this particular claim $moreClaimsQuery = $moreClaimsQuery->order(['Claims.fee' => 'DESC', 'RAND()' => 'DESC']); } $moreClaims = $moreClaimsQuery->toArray(); -- 2.45.2 From c003a6b23a053910cf7c3f475954e882c58c91ca Mon Sep 17 00:00:00 2001 From: Akinwale Ariwodola Date: Wed, 28 Oct 2020 15:43:38 +0100 Subject: [PATCH 4/8] fix select field list --- src/Controller/MainController.php | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/Controller/MainController.php b/src/Controller/MainController.php index 6db2f03..c1a60d5 100644 --- a/src/Controller/MainController.php +++ b/src/Controller/MainController.php @@ -220,9 +220,8 @@ class MainController extends AppController { if (isset($claim->publisher) || $claim->claim_type == 1) { // find more claims for the publisher $moreClaimsQuery = $this->Claims->find()->select([ - 'claim_id', 'bid_state', 'price', 'fee', 'fee_currency', 'is_nsfw', 'claim_type', - 'name', 'title', 'description', 'content_type', 'language', 'author', 'license', - 'content_type' + 'claim_id', 'bid_state', 'fee', 'fee_currency', 'is_nsfw', 'claim_type', 'name', + 'title', 'description', 'content_type', 'language', 'author', 'license', 'content_type' ])->select(['publisher' => 'C.name'])->leftJoin(['C' => 'claim'], ['C.claim_id = Claims.publisher_id'])->where(['Claims.claim_type' => 1, 'Claims.id <>' => $claim->id, 'Claims.publisher_id' => isset($claim->publisher) ? $claim->publisher_id : $claim->claim_id])->limit(9); if (isset($claim->publisher) && $claim->publisher->claim_id !== 'f2cf43b86b9d70175dc22dbb9ff7806241d90780') { // prevent ORDER BY for this particular claim $moreClaimsQuery = $moreClaimsQuery->order(['Claims.fee' => 'DESC', 'RAND()' => 'DESC']); -- 2.45.2 From 179f9c9339bd0290ddd6d8697f236731ce194f4e Mon Sep 17 00:00:00 2001 From: Akinwale Ariwodola Date: Wed, 28 Oct 2020 15:50:45 +0100 Subject: [PATCH 5/8] use publisher_id --- src/Controller/MainController.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Controller/MainController.php b/src/Controller/MainController.php index c1a60d5..d91a11f 100644 --- a/src/Controller/MainController.php +++ b/src/Controller/MainController.php @@ -223,7 +223,7 @@ class MainController extends AppController { 'claim_id', 'bid_state', 'fee', 'fee_currency', 'is_nsfw', 'claim_type', 'name', 'title', 'description', 'content_type', 'language', 'author', 'license', 'content_type' ])->select(['publisher' => 'C.name'])->leftJoin(['C' => 'claim'], ['C.claim_id = Claims.publisher_id'])->where(['Claims.claim_type' => 1, 'Claims.id <>' => $claim->id, 'Claims.publisher_id' => isset($claim->publisher) ? $claim->publisher_id : $claim->claim_id])->limit(9); - if (isset($claim->publisher) && $claim->publisher->claim_id !== 'f2cf43b86b9d70175dc22dbb9ff7806241d90780') { // prevent ORDER BY for this particular claim + if (isset($claim->publisher) && $claim->publisher_id !== 'f2cf43b86b9d70175dc22dbb9ff7806241d90780') { // prevent ORDER BY for this particular claim $moreClaimsQuery = $moreClaimsQuery->order(['Claims.fee' => 'DESC', 'RAND()' => 'DESC']); } $moreClaims = $moreClaimsQuery->toArray(); -- 2.45.2 From 4f49235511df0ecaf3078af427d13ad4a6438096 Mon Sep 17 00:00:00 2001 From: Akinwale Ariwodola Date: Wed, 28 Oct 2020 15:51:45 +0100 Subject: [PATCH 6/8] add created_at to field list --- src/Controller/MainController.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Controller/MainController.php b/src/Controller/MainController.php index d91a11f..ae3462e 100644 --- a/src/Controller/MainController.php +++ b/src/Controller/MainController.php @@ -221,7 +221,8 @@ class MainController extends AppController { // find more claims for the publisher $moreClaimsQuery = $this->Claims->find()->select([ 'claim_id', 'bid_state', 'fee', 'fee_currency', 'is_nsfw', 'claim_type', 'name', - 'title', 'description', 'content_type', 'language', 'author', 'license', 'content_type' + 'title', 'description', 'content_type', 'language', 'author', 'license', 'content_type', + 'created_at' ])->select(['publisher' => 'C.name'])->leftJoin(['C' => 'claim'], ['C.claim_id = Claims.publisher_id'])->where(['Claims.claim_type' => 1, 'Claims.id <>' => $claim->id, 'Claims.publisher_id' => isset($claim->publisher) ? $claim->publisher_id : $claim->claim_id])->limit(9); if (isset($claim->publisher) && $claim->publisher_id !== 'f2cf43b86b9d70175dc22dbb9ff7806241d90780') { // prevent ORDER BY for this particular claim $moreClaimsQuery = $moreClaimsQuery->order(['Claims.fee' => 'DESC', 'RAND()' => 'DESC']); -- 2.45.2 From ecbd1c82cf1b3854789b4de0cfd6c722ab6dc86a Mon Sep 17 00:00:00 2001 From: Akinwale Ariwodola Date: Wed, 28 Oct 2020 15:55:11 +0100 Subject: [PATCH 7/8] skip more claims query --- src/Controller/MainController.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/Controller/MainController.php b/src/Controller/MainController.php index ae3462e..ed9fd7f 100644 --- a/src/Controller/MainController.php +++ b/src/Controller/MainController.php @@ -226,8 +226,10 @@ class MainController extends AppController { ])->select(['publisher' => 'C.name'])->leftJoin(['C' => 'claim'], ['C.claim_id = Claims.publisher_id'])->where(['Claims.claim_type' => 1, 'Claims.id <>' => $claim->id, 'Claims.publisher_id' => isset($claim->publisher) ? $claim->publisher_id : $claim->claim_id])->limit(9); if (isset($claim->publisher) && $claim->publisher_id !== 'f2cf43b86b9d70175dc22dbb9ff7806241d90780') { // prevent ORDER BY for this particular claim $moreClaimsQuery = $moreClaimsQuery->order(['Claims.fee' => 'DESC', 'RAND()' => 'DESC']); + $moreClaims = $moreClaimsQuery->toArray(); + } else { + $moreClaims = []; } - $moreClaims = $moreClaimsQuery->toArray(); for ($i = 0; $i < count($moreClaims); $i++) { if ($canConvert && $moreClaims[$i]->fee > 0 && $moreClaims[$i]->fee_currency == 'USD') { $moreClaims[$i]->price = $moreClaims[$i]->fee / $priceInfo->price; -- 2.45.2 From f08049dc5cf569e1a8d0d1e5371cbda5b496170f Mon Sep 17 00:00:00 2001 From: Akinwale Ariwodola Date: Wed, 28 Oct 2020 15:56:09 +0100 Subject: [PATCH 8/8] remove redundant code --- src/Controller/MainController.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/Controller/MainController.php b/src/Controller/MainController.php index ed9fd7f..49cbb4e 100644 --- a/src/Controller/MainController.php +++ b/src/Controller/MainController.php @@ -227,8 +227,6 @@ class MainController extends AppController { if (isset($claim->publisher) && $claim->publisher_id !== 'f2cf43b86b9d70175dc22dbb9ff7806241d90780') { // prevent ORDER BY for this particular claim $moreClaimsQuery = $moreClaimsQuery->order(['Claims.fee' => 'DESC', 'RAND()' => 'DESC']); $moreClaims = $moreClaimsQuery->toArray(); - } else { - $moreClaims = []; } for ($i = 0; $i < count($moreClaims); $i++) { if ($canConvert && $moreClaims[$i]->fee > 0 && $moreClaims[$i]->fee_currency == 'USD') { -- 2.45.2