From 483e5542595aba2d8a1ab4d1c94f1688dbb458a3 Mon Sep 17 00:00:00 2001 From: Sebastian Grewe Date: Sun, 30 Jun 2013 11:04:12 +0200 Subject: [PATCH] Adding SQL based pagination to admin transactions This will prevent PHP OOM errors due to a large amount of transactions. You can find navigation arrows at the top and fetch 30 transactions at a time. Fixes #267 --- public/include/classes/transaction.class.php | 7 +-- .../include/pages/admin/transactions.inc.php | 2 +- .../mmcFE/admin/transactions/default.tpl | 47 ++++++++++--------- 3 files changed, 29 insertions(+), 27 deletions(-) diff --git a/public/include/classes/transaction.class.php b/public/include/classes/transaction.class.php index a432b65b..2d65657b 100644 --- a/public/include/classes/transaction.class.php +++ b/public/include/classes/transaction.class.php @@ -113,7 +113,7 @@ class Transaction { * @param none * @return mixed array or false **/ - public function getAllTransactions() { + public function getAllTransactions($start=0) { $this->debug->append("STA " . __METHOD__, 4); $stmt = $this->mysqli->prepare(" SELECT @@ -128,8 +128,9 @@ class Transaction { FROM transactions AS t LEFT JOIN " . $this->block->getTableName() . " AS b ON t.block_id = b.id LEFT JOIN " . $this->user->getTableName() . " AS a ON t.account_id = a.id - ORDER BY id DESC"); - if ($this->checkStmt($stmt) && $stmt->execute() && $result = $stmt->get_result()) + ORDER BY id DESC + LIMIT ?,30"); + if ($this->checkStmt($stmt) && $stmt->bind_param('i', $start) && $stmt->execute() && $result = $stmt->get_result()) return $result->fetch_all(MYSQLI_ASSOC); $this->debug->append('Unable to fetch transactions'); return false; diff --git a/public/include/pages/admin/transactions.inc.php b/public/include/pages/admin/transactions.inc.php index 93d4530d..00345903 100644 --- a/public/include/pages/admin/transactions.inc.php +++ b/public/include/pages/admin/transactions.inc.php @@ -3,7 +3,7 @@ // Make sure we are called from index.php if (!defined('SECURITY')) die('Hacking attempt'); if ($user->isAuthenticated()) { - $aTransactions = $transaction->getAllTransactions(); + $aTransactions = $transaction->getAllTransactions(@$_REQUEST['start']); if (!$aTransactions) $_SESSION['POPUP'][] = array('CONTENT' => 'Could not find any transaction', 'TYPE' => 'errormsg'); $smarty->assign('TRANSACTIONS', $aTransactions); $smarty->assign('CONTENT', 'default.tpl'); diff --git a/public/templates/mmcFE/admin/transactions/default.tpl b/public/templates/mmcFE/admin/transactions/default.tpl index c6497246..492b1a97 100644 --- a/public/templates/mmcFE/admin/transactions/default.tpl +++ b/public/templates/mmcFE/admin/transactions/default.tpl @@ -1,12 +1,15 @@ {include file="global/block_header.tpl" BLOCK_HEADER="Transaction Log" BUTTONS=array(Confirmed,Unconfirmed,Orphan)} +
+ + +
- {include file="global/pagination.tpl"} - @@ -27,6 +30,7 @@ or $TRANSACTIONS[transaction].type == 'Debit_MP' or $TRANSACTIONS[transaction].type == 'TXFee' )} + {assign var=confirmed value=1} @@ -34,10 +38,15 @@ - + {/if} {/section} + {if $confirmed != 1} + + + + {/if}
TX #Account + Account Date TX Type Payment Address
{$TRANSACTIONS[transaction].id} {$TRANSACTIONS[transaction].username}{$TRANSACTIONS[transaction].type} {$TRANSACTIONS[transaction].coin_address} {if $TRANSACTIONS[transaction].height == 0}n/a{else}{$TRANSACTIONS[transaction].height}{/if}{$TRANSACTIONS[transaction].amount}{$TRANSACTIONS[transaction].amount|number_format:"8"}
No confirmed transactions

@@ -49,12 +58,11 @@

- {include file="global/pagination.tpl" ID=2} - @@ -69,6 +77,7 @@ or ($TRANSACTIONS[transaction].type == 'Donation' and $TRANSACTIONS[transaction].confirmations < $GLOBAL.confirmations) or ($TRANSACTIONS[transaction].type == 'Fee' and $TRANSACTIONS[transaction].confirmations < $GLOBAL.confirmations) )} + {assign var=unconfirmed value=1} @@ -76,19 +85,15 @@ - + - {if $TRANSACTIONS[transaction].type == 'Credit' or $TRANSACTIONS[transaction].type == 'Bonus'} - {assign var="credits" value="`$credits+$TRANSACTIONS[transaction].amount`"} - {else} - {assign var="debits" value="`$debits+$TRANSACTIONS[transaction].amount`"} - {/if} {/if} {/section} + {if $unconfirmed != 1} - - + + {/if}
TX #Account + Account Date TX Type Payment Address
{$TRANSACTIONS[transaction].id} {$TRANSACTIONS[transaction].username}{$TRANSACTIONS[transaction].type} {$TRANSACTIONS[transaction].coin_address} {if $TRANSACTIONS[transaction].height == 0}n/a{else}{$TRANSACTIONS[transaction].height}{/if}{$TRANSACTIONS[transaction].amount}{$TRANSACTIONS[transaction].amount|number_format:"8"}
Unconfirmed Totals:{$credits|default - $debits|default}No unconfirmed transactions

Listed are your estimated rewards and donations/fees for all blocks awaiting {$GLOBAL.confirmations} confirmations.

@@ -96,12 +101,11 @@
- {include file="global/pagination.tpl"} - @@ -117,6 +121,7 @@ or $TRANSACTIONS[transaction].type == 'Orphan_Fee' or $TRANSACTIONS[transaction].type == 'Orphan_Bonus' )} + {assign var=orphaned value=1} @@ -124,19 +129,15 @@ - + - {if $TRANSACTIONS[transaction].type == 'Orphan_Credit' or $TRANSACTIONS[transaction].type == 'Orphan_Bonus'} - {assign var="orphan_credits" value="`$orphan_credits+$TRANSACTIONS[transaction].amount`"} - {else} - {assign var="orphan_debits" value="`$orphan_debits+$TRANSACTIONS[transaction].amount`"} - {/if} {/if} {/section} + {if $orphaned != 1} - - + + {/if}
TX #Account + Account Date TX Type Payment Address
{$TRANSACTIONS[transaction].id} {$TRANSACTIONS[transaction].username}{$TRANSACTIONS[transaction].type} {$TRANSACTIONS[transaction].coin_address} {if $TRANSACTIONS[transaction].height == 0}n/a{else}{$TRANSACTIONS[transaction].height}{/if}{$TRANSACTIONS[transaction].amount}{$TRANSACTIONS[transaction].amount|number_format:"8"}
Orphaned Totals:{$orphan_credits|default - $orphan_debits|default}No orphan transactions

Listed are your orphaned transactions for blocks not part of the main blockchain.