Skip to content

Commit

Permalink
Cache tracker enabled per table
Browse files Browse the repository at this point in the history
This can be executed quite a lot of times during import and there is no
reason to query database again during that.

Fixes #13318

Signed-off-by: Michal Čihař <michal@cihar.com>
  • Loading branch information
nijel committed Jun 13, 2017
1 parent 5fd7b2c commit 4f30297
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
1 change: 1 addition & 0 deletions ChangeLog
Expand Up @@ -14,6 +14,7 @@ phpMyAdmin - ChangeLog
- issue #13092 Gracefully handle early fatal errors in AJAX requests
- issue #13327 Fixed Incorrect NavigationTreeEnableExpansion default value in the documentation
- issue #13008 Fixed export of database with a lot of tables
- issue #13318 Improved performance when importing with enabled tracking

4.7.1 (2017-05-25)
- issue #13132 Always execute tracking queries as controluser
Expand Down
15 changes: 13 additions & 2 deletions libraries/Tracker.php
Expand Up @@ -23,6 +23,11 @@ class Tracker
*/
static protected $enabled = false;

/**
* Cache to avoid quering tracking status multiple times.
*/
static protected $_tracking_cache = array();

/**
* Actually enables tracking. This needs to be done after all
* underlaying code is initialized.
Expand Down Expand Up @@ -111,6 +116,10 @@ static public function isTracked($dbname, $tablename)
if (! self::$enabled) {
return false;
}

if (isset(self::$_tracking_cache[$dbname][$tablename])) {
return self::$_tracking_cache[$dbname][$tablename];
}
/* We need to avoid attempt to track any queries
* from PMA_getRelationsParam
*/
Expand All @@ -127,9 +136,11 @@ static public function isTracked($dbname, $tablename)
" AND table_name = '" . $GLOBALS['dbi']->escapeString($tablename) . "' " .
" ORDER BY version DESC LIMIT 1";

$result = $GLOBALS['dbi']->fetchValue($sql_query, 0, 0, $GLOBALS['controllink']);
$result = $GLOBALS['dbi']->fetchValue($sql_query, 0, 0, $GLOBALS['controllink']) == 1;

self::$_tracking_cache[$dbname][$tablename] = $result;

return ($result == 1);
return $result;
}

/**
Expand Down

0 comments on commit 4f30297

Please sign in to comment.