From 9d88e2eaec5721b43390249b7a2c66d2633bcfd1 Mon Sep 17 00:00:00 2001 From: marcdeb1 Date: Fri, 21 Dec 2018 14:18:39 +0100 Subject: [PATCH] Queries and bugs --- src/Controller/MainController.php | 10 +++++++++- src/Model/Entity/Claim.php | 7 ++----- src/Template/Main/realtime.ctp | 2 +- 3 files changed, 12 insertions(+), 7 deletions(-) diff --git a/src/Controller/MainController.php b/src/Controller/MainController.php index 8766913..86e2c5f 100644 --- a/src/Controller/MainController.php +++ b/src/Controller/MainController.php @@ -220,7 +220,15 @@ class MainController extends AppController { $blocks[$i]->transaction_count = count($tx_hashes); } - $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(); + $transactions = $this->Transactions->find()->select(['Transactions.id', 'Transactions.hash', 'Transactions.input_count', 'Transactions.output_count', 'Transactions.transaction_time', 'Transactions.created_at'])->order(['Transactions.created_at' => 'desc'])->limit(10)->toArray(); + foreach($transactions as $tx) { + $value = 0; + $outputs = $this->Outputs->find()->where(['transaction_id' => $tx->id])->toArray(); + foreach($outputs as $output) { + $value += $output->value; + } + $tx->value = $value; + } $this->set('blocks', $blocks); $this->set('txs', $transactions); diff --git a/src/Model/Entity/Claim.php b/src/Model/Entity/Claim.php index eab2204..90bbcd5 100644 --- a/src/Model/Entity/Claim.php +++ b/src/Model/Entity/Claim.php @@ -8,11 +8,8 @@ use Cake\ORM\TableRegistry; class Claim extends Entity { function getLbryLink() { $link = $this->name; - $ClaimModel = TableRegistry::get('Claims'); - $publisher = $ClaimModel->find()->select(['name'])->where(['claim_id' => $this->publisher_id])->first(); - - if (isset($publisher->name)) { - $link = $publisher->name . '/' . $link; + if (isset($this->publisher)) { + $link = $this->publisher . '/' . $link; } $link = 'lbry://' . $link; return $link; diff --git a/src/Template/Main/realtime.ctp b/src/Template/Main/realtime.ctp index 2724609..45750c0 100644 --- a/src/Template/Main/realtime.ctp +++ b/src/Template/Main/realtime.ctp @@ -153,7 +153,7 @@ - +
hash ?>
created_at->diffForHumans(); ?> input_count ?>