From 3569fdb4ff969b88aa8bc68eba228c1bae6abf4b Mon Sep 17 00:00:00 2001 From: marcdeb1 Date: Fri, 21 Dec 2018 13:55:59 +0100 Subject: [PATCH] Improved index query --- src/Controller/MainController.php | 9 ++------- src/Template/Main/index.ctp | 6 +++--- 2 files changed, 5 insertions(+), 10 deletions(-) diff --git a/src/Controller/MainController.php b/src/Controller/MainController.php index 96a4564..8766913 100644 --- a/src/Controller/MainController.php +++ b/src/Controller/MainController.php @@ -102,13 +102,7 @@ class MainController extends AppController { $hashRate = $this->_formatHashRate($this->_gethashrate()); // recent claims - $claims = $this->Claims->find()->select(['transaction_hash_id', 'name', 'vout', 'claim_id', 'claim_type', 'author', 'title', 'description', 'content_type', 'is_nsfw', 'language', 'thumbnail_url', 'created_at', 'publisher_id'])-> - distinct(['Claims.claim_id'])->order(['Claims.created_at' => 'DESC'])->limit(5)->toArray(); - - foreach($claims as $claim) { - $publisher = $this->Claims->find()->select(['name'])->where(['claim_id' => $claim->publisher_id])->first(); - $claim->publisher = $publisher; - } + $claims = $this->Claims->find()->distinct(['Claims.claim_id'])->select($this->Claims)->select(['publisher' => 'C.name'])->leftJoin(['C' => 'claim'], ['C.claim_id = Claims.publisher_id'])->order(['Claims.created_at' => 'DESC'])->limit(5)->toArray(); $this->set('recentBlocks', $blocks); $this->set('recentClaims', $claims); @@ -227,6 +221,7 @@ class MainController extends AppController { } $transactions = $this->Transactions->find()->select(['Transactions.id', 'Transactions.hash', 'Transactions.input_count', 'Transactions.output_count', 'Transactions.transaction_time', 'Transactions.created_at'])->select(['value' => 'sum(O.value)'])->leftJoin(['O' => 'output'], ['O.transaction_id = Transactions.id'])->order(['Transactions.created_at' => 'desc'])->limit(10)->toArray(); + $this->set('blocks', $blocks); $this->set('txs', $transactions); } diff --git a/src/Template/Main/index.ctp b/src/Template/Main/index.ctp index 8bd3aed..fedcf93 100644 --- a/src/Template/Main/index.ctp +++ b/src/Template/Main/index.ctp @@ -189,9 +189,9 @@ $autoThumbText = $claim->getAutoThumbText(); $link = $claim->name; $rawLink = $claim->name; - if (isset($claim->publisher->name)) { - $link = urlencode($claim->publisher->name) . '/' . $link; - $rawLink = $claim->publisher->name . '/' . $link; + if (isset($claim->publisher)) { + $link = urlencode($claim->publisher) . '/' . $link; + $rawLink = $claim->publisher . '/' . $link; } $link = 'lbry://' . $link; $rawLink = 'lbry://' . $rawLink;