[IMPROVED] Transaction data handling

This will improve loading times on large transaction tables. Thanks
@feeleep75 for helping with this one.

* Do not use SQL_CALC_NUM_ROWS since it will do a full table scan
* Allow admins to disable account transaction summaries to speed up page
  loads on large tables
* added new admin setting under system to Disable TX Summaries

Fixes #1065 once merged
This commit is contained in:
Sebastian Grewe 2013-12-23 10:48:12 +01:00
parent 4b181201e4
commit 51a996573d
6 changed files with 31 additions and 39 deletions

View File

@ -102,7 +102,6 @@ class Transaction extends Base {
$this->debug->append("STA " . __METHOD__, 4); $this->debug->append("STA " . __METHOD__, 4);
$sql = " $sql = "
SELECT SELECT
SQL_CALC_FOUND_ROWS
t.id AS id, t.id AS id,
a.username as username, a.username as username,
t.type AS type, t.type AS type,
@ -160,21 +159,13 @@ class Transaction extends Base {
$sql .= implode(' AND ', $aFilter); $sql .= implode(' AND ', $aFilter);
} }
} }
$sql .= " $sql .= " ORDER BY id DESC LIMIT ?,?";
ORDER BY id DESC
LIMIT ?,?
";
// Add some other params to query // Add some other params to query
$this->addParam('i', $start); $this->addParam('i', $start);
$this->addParam('i', $limit); $this->addParam('i', $limit);
$stmt = $this->mysqli->prepare($sql); $stmt = $this->mysqli->prepare($sql);
if ($this->checkStmt($stmt) && call_user_func_array( array($stmt, 'bind_param'), $this->getParam()) && $stmt->execute() && $result = $stmt->get_result()) { if ($this->checkStmt($stmt) && call_user_func_array( array($stmt, 'bind_param'), $this->getParam()) && $stmt->execute() && $result = $stmt->get_result())
// Fetch matching row count
$num_rows = $this->mysqli->prepare("SELECT FOUND_ROWS() AS num_rows");
if ($num_rows->execute() && $row_count = $num_rows->get_result()->fetch_object()->num_rows)
$this->num_rows = $row_count;
return $result->fetch_all(MYSQLI_ASSOC); return $result->fetch_all(MYSQLI_ASSOC);
}
return $this->sqlError(); return $this->sqlError();
} }

View File

@ -287,6 +287,13 @@ $aSettings['system'][] = array(
'name' => 'disable_dashboard_api', 'value' => $setting->getValue('disable_dashboard_api'), 'name' => 'disable_dashboard_api', 'value' => $setting->getValue('disable_dashboard_api'),
'tooltip' => 'Disable dashboard API entirely to reduce server load.' 'tooltip' => 'Disable dashboard API entirely to reduce server load.'
); );
$aSettings['system'][] = array(
'display' => 'Disable TX Summaries', 'type' => 'select',
'options' => array( 0 => 'No', 1 => 'Yes'),
'default' => 0,
'name' => 'disable_transactionsummary', 'value' => $setting->getValue('disable_transactionsummary'),
'tooltip' => 'Disable transaction summaries. Helpful with large transaction tables.'
);
$aSettings['recaptcha'][] = array( $aSettings['recaptcha'][] = array(
'display' => 'Enable re-Captcha', 'type' => 'select', 'display' => 'Enable re-Captcha', 'type' => 'select',
'options' => array( 0 => 'No', 1 => 'Yes' ), 'options' => array( 0 => 'No', 1 => 'Yes' ),

View File

@ -6,16 +6,17 @@ if ($user->isAuthenticated()) {
$iLimit = 30; $iLimit = 30;
empty($_REQUEST['start']) ? $start = 0 : $start = $_REQUEST['start']; empty($_REQUEST['start']) ? $start = 0 : $start = $_REQUEST['start'];
$aTransactions = $transaction->getTransactions($start, @$_REQUEST['filter'], $iLimit, $_SESSION['USERDATA']['id']); $aTransactions = $transaction->getTransactions($start, @$_REQUEST['filter'], $iLimit, $_SESSION['USERDATA']['id']);
$aTransactionSummary = $transaction->getTransactionSummary($_SESSION['USERDATA']['id']);
$iCountTransactions = $transaction->num_rows;
$aTransactionTypes = $transaction->getTypes(); $aTransactionTypes = $transaction->getTypes();
if (!$aTransactions) $_SESSION['POPUP'][] = array('CONTENT' => 'Could not find any transaction', 'TYPE' => 'errormsg'); if (!$aTransactions) $_SESSION['POPUP'][] = array('CONTENT' => 'Could not find any transaction', 'TYPE' => 'errormsg');
if (!$setting->getValue('disable_transactionsummary')) {
$aTransactionSummary = $transaction->getTransactionSummary($_SESSION['USERDATA']['id']);
$smarty->assign('SUMMARY', $aTransactionSummary);
}
$smarty->assign('LIMIT', $iLimit); $smarty->assign('LIMIT', $iLimit);
$smarty->assign('TRANSACTIONS', $aTransactions); $smarty->assign('TRANSACTIONS', $aTransactions);
$smarty->assign('SUMMARY', $aTransactionSummary);
$smarty->assign('TRANSACTIONTYPES', $aTransactionTypes); $smarty->assign('TRANSACTIONTYPES', $aTransactionTypes);
$smarty->assign('TXSTATUS', array('' => '', 'Confirmed' => 'Confirmed', 'Unconfirmed' => 'Unconfirmed', 'Orphan' => 'Orphan')); $smarty->assign('TXSTATUS', array('' => '', 'Confirmed' => 'Confirmed', 'Unconfirmed' => 'Unconfirmed', 'Orphan' => 'Orphan'));
$smarty->assign('COUNTTRANSACTIONS', $iCountTransactions); $smarty->assign('DISABLE_TRANSACTIONSUMMARY', $setting->getValue('disable_transactionsummary'));
} }
$smarty->assign('CONTENT', 'default.tpl'); $smarty->assign('CONTENT', 'default.tpl');
?> ?>

View File

@ -14,16 +14,17 @@ if (!$smarty->isCached('master.tpl', $smarty_cache_key)) {
$debug->append('No cached version available, fetching from backend', 3); $debug->append('No cached version available, fetching from backend', 3);
empty($_REQUEST['start']) ? $start = 0 : $start = $_REQUEST['start']; empty($_REQUEST['start']) ? $start = 0 : $start = $_REQUEST['start'];
$aTransactions = $transaction->getTransactions($start, @$_REQUEST['filter'], $iLimit); $aTransactions = $transaction->getTransactions($start, @$_REQUEST['filter'], $iLimit);
$aTransactionSummary = $transaction->getTransactionSummary();
$iCountTransactions = $transaction->num_rows;
$aTransactionTypes = $transaction->getTypes(); $aTransactionTypes = $transaction->getTypes();
if (!$aTransactions) $_SESSION['POPUP'][] = array('CONTENT' => 'Could not find any transaction', 'TYPE' => 'errormsg'); if (!$aTransactions) $_SESSION['POPUP'][] = array('CONTENT' => 'Could not find any transaction', 'TYPE' => 'errormsg');
if (!$setting->getValue('disable_transactionsummary')) {
$aTransactionSummary = $transaction->getTransactionSummary();
$smarty->assign('SUMMARY', $aTransactionSummary);
}
$smarty->assign('LIMIT', $iLimit); $smarty->assign('LIMIT', $iLimit);
$smarty->assign('TRANSACTIONS', $aTransactions); $smarty->assign('TRANSACTIONS', $aTransactions);
$smarty->assign('SUMMARY', $aTransactionSummary);
$smarty->assign('TRANSACTIONTYPES', $aTransactionTypes); $smarty->assign('TRANSACTIONTYPES', $aTransactionTypes);
$smarty->assign('TXSTATUS', array('' => '', 'Confirmed' => 'Confirmed', 'Unconfirmed' => 'Unconfirmed', 'Orphan' => 'Orphan')); $smarty->assign('TXSTATUS', array('' => '', 'Confirmed' => 'Confirmed', 'Unconfirmed' => 'Unconfirmed', 'Orphan' => 'Orphan'));
$smarty->assign('COUNTTRANSACTIONS', $iCountTransactions); $smarty->assign('DISABLE_TRANSACTIONSUMMARY', $setting->getValue('disable_transactionsummary'));
} else { } else {
$debug->append('Using cached page', 3); $debug->append('Using cached page', 3);
} }

View File

@ -1,3 +1,4 @@
{if $DISABLE_TRANSACTIONSUMMARY|default:"0" != 1}
<article class="module width_full"> <article class="module width_full">
<header><h3>Transaction Summary</h3></header> <header><h3>Transaction Summary</h3></header>
<table class="tablesorter" cellspacing="0"> <table class="tablesorter" cellspacing="0">
@ -17,6 +18,7 @@
</tbody> </tbody>
</table> </table>
</article> </article>
{/if}
<article class="module width_quarter"> <article class="module width_quarter">
<header><h3>Transaction Filter</h3></header> <header><h3>Transaction Filter</h3></header>
@ -27,21 +29,15 @@
<table cellspacing="0" class="tablesorter"> <table cellspacing="0" class="tablesorter">
<tbody> <tbody>
<tr> <tr>
{if $COUNTTRANSACTIONS / $LIMIT > 1}
<td align="left"> <td align="left">
{if $smarty.request.start|default:"0" > 0} {if $smarty.request.start|default:"0" > 0}
<a href="{$smarty.server.PHP_SELF}?page={$smarty.request.page|escape}&action={$smarty.request.action|escape}&start={$smarty.request.start|escape|default:"0" - $LIMIT}{if $FILTERS|default:""}{$FILTERS}{/if}"><i class="icon-left-open"></i></a> <a href="{$smarty.server.PHP_SELF}?page={$smarty.request.page|escape}&action={$smarty.request.action|escape}&start={$smarty.request.start|escape|default:"0" - $LIMIT}{if $FILTERS|default:""}{$FILTERS}{/if}"><i class="icon-left-open"></i></a>
{else} {else}
<i class="icon-left-open"></i> <i class="icon-left-open"></i>
{/if} {/if}
</td> </td>
<td align="right"> <td align="right">
{if $COUNTTRANSACTIONS - $smarty.request.start|default:"0" - $LIMIT > 0}
<a href="{$smarty.server.PHP_SELF}?page={$smarty.request.page|escape}&action={$smarty.request.action|escape}&start={$smarty.request.start|escape|default:"0" + $LIMIT}{if $FILTERS|default:""}{$FILTERS}{/if}"><i class="icon-right-open"></i></a> <a href="{$smarty.server.PHP_SELF}?page={$smarty.request.page|escape}&action={$smarty.request.action|escape}&start={$smarty.request.start|escape|default:"0" + $LIMIT}{if $FILTERS|default:""}{$FILTERS}{/if}"><i class="icon-right-open"></i></a>
{else}
<i class="icon-right-open"></i>
{/if}
{/if}
</td> </td>
</tr> </tr>
</tbody> </tbody>

View File

@ -1,3 +1,4 @@
{if $DISABLE_TRANSACTIONSUMMARY|default:"0" != 1}
<article class="module width_full"> <article class="module width_full">
<header><h3>Transaction Summary</h3></header> <header><h3>Transaction Summary</h3></header>
<table class="tablesorter" cellspacing="0"> <table class="tablesorter" cellspacing="0">
@ -17,6 +18,7 @@
</tbody> </tbody>
</table> </table>
</article> </article>
{/if}
<article class="module width_quarter"> <article class="module width_quarter">
<header><h3>Transaction Filter</h3></header> <header><h3>Transaction Filter</h3></header>
@ -27,21 +29,15 @@
<table cellspacing="0" class="tablesorter"> <table cellspacing="0" class="tablesorter">
<tbody> <tbody>
<tr> <tr>
{if $COUNTTRANSACTIONS / $LIMIT > 1}
<td align="left"> <td align="left">
{if $smarty.request.start|default:"0" > 0} {if $smarty.request.start|default:"0" > 0}
<a href="{$smarty.server.PHP_SELF}?page={$smarty.request.page|escape}&action={$smarty.request.action|escape}&start={$smarty.request.start|default:"0" - $LIMIT}{if $FILTERS|default:""}{$FILTERS}{/if}"><i class="icon-left-open"></i></a> <a href="{$smarty.server.PHP_SELF}?page={$smarty.request.page|escape}&action={$smarty.request.action|escape}&start={$smarty.request.start|escape|default:"0" - $LIMIT}{if $FILTERS|default:""}{$FILTERS}{/if}"><i class="icon-left-open"></i></a>
{else} {else}
<i class="icon-left-open"></i> <i class="icon-left-open"></i>
{/if} {/if}
</td> </td>
<td align="right"> <td align="right">
{if $COUNTTRANSACTIONS - $smarty.request.start|default:"0" - $LIMIT > 0} <a href="{$smarty.server.PHP_SELF}?page={$smarty.request.page|escape}&action={$smarty.request.action|escape}&start={$smarty.request.start|escape|default:"0" + $LIMIT}{if $FILTERS|default:""}{$FILTERS}{/if}"><i class="icon-right-open"></i></a>
<a href="{$smarty.server.PHP_SELF}?page={$smarty.request.page|escape}&action={$smarty.request.action|escape}&start={$smarty.request.start|default:"0" + $LIMIT}{if $FILTERS|default:""}{$FILTERS}{/if}"><i class="icon-right-open"></i></a>
{else}
<i class="icon-right-open"></i>
{/if}
{/if}
</td> </td>
</tbody> </tbody>
</table> </table>