Time out long running select count

This commit is contained in:
Jakub Vrana 2012-08-19 19:38:53 -07:00
parent 1f53cd3386
commit 6a7021db28
3 changed files with 22 additions and 15 deletions

View file

@ -905,6 +905,7 @@ function is_url($string) {
function kill_timeout() {
global $adminer, $token;
$kill = mt_rand();
if (support("kill")) {
?>
<script type="text/javascript">
var timeout = setTimeout(function () {
@ -913,6 +914,7 @@ var timeout = setTimeout(function () {
}, <?php echo 1000 * $adminer->queryTimeout(); ?>);
</script>
<?php
}
ob_flush();
flush();
return $kill;
@ -923,13 +925,15 @@ var timeout = setTimeout(function () {
*/
function cancel_kill_timeout() {
global $connection;
echo "<script type='text/javascript'>clearTimeout(timeout);</script>\n";
ob_flush();
flush();
if ($connection->errno == 2006) { // 2006 - CR_SERVER_GONE_ERROR
$connection2 = connect();
if (is_object($connection2)) {
$connection = $connection2;
if (support("kill")) {
echo "<script type='text/javascript'>clearTimeout(timeout);</script>\n";
ob_flush();
flush();
if ($connection->errno == 2006) { // 2006 - CR_SERVER_GONE_ERROR
$connection2 = connect();
if (is_object($connection2)) {
$connection = $connection2;
}
}
}
}

View file

@ -393,25 +393,28 @@ if (!$columns) {
$found_rows = found_rows($table_status, $where);
if ($found_rows < max(1e4, 2 * ($page + 1) * $limit)) {
// slow with big tables
ob_flush();
flush();
$found_rows = $connection->result("SELECT COUNT(*) FROM " . table($TABLE) . ($where ? " WHERE " . implode(" AND ", $where) : ""));
$kill = kill_timeout();
$found_rows = @$connection->result("/* Adminer $kill */ SELECT COUNT(*) FROM " . table($TABLE) . ($where ? " WHERE " . implode(" AND ", $where) : "")); // @ - may be kill
cancel_kill_timeout();
} else {
$exact_count = false;
}
}
echo "<p class='pages'>";
if (+$limit && $found_rows > $limit) {
if (+$limit && ($found_rows === false || $found_rows > $limit)) {
// display first, previous 4, next 4 and last page
$max_page = floor(($found_rows - 1) / $limit);
$max_page = ($found_rows === false
? $page + (count($rows) >= $limit ? 2 : 1)
: floor(($found_rows - 1) / $limit)
);
echo '<a href="' . h(remove_from_uri("page")) . "\" onclick=\"pageClick(this.href, +prompt('" . lang('Page') . "', '" . ($page + 1) . "'), event); return false;\">" . lang('Page') . "</a>:";
echo pagination(0, $page) . ($page > 5 ? " ..." : "");
for ($i = max(1, $page - 4); $i < min($max_page, $page + 5); $i++) {
echo pagination($i, $page);
}
echo ($page + 5 < $max_page ? " ..." : "") . ($exact_count ? pagination($max_page, $page) : ' <a href="' . h(remove_from_uri() . "&page=last") . '">' . lang('last') . "</a>");
echo ($page + 5 < $max_page ? " ..." : "") . ($exact_count && $found_rows !== false ? pagination($max_page, $page) : ' <a href="' . h(remove_from_uri() . "&page=last") . '">' . lang('last') . "</a>");
}
echo " (" . ($exact_count ? "" : "~ ") . lang('%d row(s)', $found_rows) . ") " . checkbox("all", 1, 0, lang('whole result')) . "\n";
echo ($found_rows !== false ? " (" . ($exact_count ? "" : "~ ") . lang('%d row(s)', $found_rows) . ")" : "") . " " . checkbox("all", 1, 0, lang('whole result')) . "\n";
if ($adminer->selectCommandPrint()) {
?>

View file

@ -1,6 +1,6 @@
Adminer 3.5.2-dev:
Edit strings with \n in textarea
Time out long running database list
Time out long running database list and select count
Use VALUES() in INSERT+UPDATE export
Style logout button as link