]> gitweb.fluxo.info Git - lorea/elgg.git/commitdiff
introduces _elgg_invalidate_query_cache() to dry up the db query cache code
authorcash <cash.costello@gmail.com>
Sat, 13 Apr 2013 18:10:02 +0000 (14:10 -0400)
committercash <cash.costello@gmail.com>
Sat, 13 Apr 2013 18:10:02 +0000 (14:10 -0400)
engine/classes/ElggBatch.php
engine/lib/database.php
engine/lib/upgrade.php
engine/lib/upgrades/2009102801.php
engine/lib/upgrades/2010061501.php
engine/lib/upgrades/2010071001.php
engine/lib/upgrades/2010071002.php
engine/lib/upgrades/2011052801.php
engine/lib/upgrades/2013030600-1.8.13-update_user_location-8999eb8bf1bdd9a3.php

index 5d59425d0df7e04edc28871967ad66f244565e6f..1912f89a2520274edac343e5546b6755e2563197 100644 (file)
@@ -229,8 +229,9 @@ class ElggBatch
        private function getNextResultsChunk() {
                // reset memory caches after first chunk load
                if ($this->chunkIndex > 0) {
-                       global $DB_QUERY_CACHE, $ENTITY_CACHE;
-                       $DB_QUERY_CACHE = $ENTITY_CACHE = array();
+                       global $ENTITY_CACHE;
+                       $ENTITY_CACHE = array();
+                       _elgg_invalidate_query_cache();
                }
 
                // always reset results.
index 18235149dda259f51a0c62998e044e04e5b274a1..b41eb4cda51728701585c0a317857fabf8b8e821 100644 (file)
@@ -460,19 +460,12 @@ function elgg_query_runner($query, $callback = null, $single = false) {
  * @access private
  */
 function insert_data($query) {
-       global $DB_QUERY_CACHE;
 
        elgg_log("DB query $query", 'NOTICE');
        
        $dblink = get_db_link('write');
 
-       // Invalidate query cache
-       if ($DB_QUERY_CACHE) {
-               /* @var ElggStaticVariableCache $DB_QUERY_CACHE */
-               $DB_QUERY_CACHE->clear();
-       }
-
-       elgg_log("Query cache invalidated", 'NOTICE');
+       _elgg_invalidate_query_cache();
 
        if (execute_query("$query", $dblink)) {
                return mysql_insert_id($dblink);
@@ -492,18 +485,12 @@ function insert_data($query) {
  * @access private
  */
 function update_data($query) {
-       global $DB_QUERY_CACHE;
 
        elgg_log("DB query $query", 'NOTICE');
 
        $dblink = get_db_link('write');
 
-       // Invalidate query cache
-       if ($DB_QUERY_CACHE) {
-               /* @var ElggStaticVariableCache $DB_QUERY_CACHE */
-               $DB_QUERY_CACHE->clear();
-               elgg_log("Query cache invalidated", 'NOTICE');
-       }
+       _elgg_invalidate_query_cache();
 
        if (execute_query("$query", $dblink)) {
                return TRUE;
@@ -523,18 +510,12 @@ function update_data($query) {
  * @access private
  */
 function delete_data($query) {
-       global $DB_QUERY_CACHE;
 
        elgg_log("DB query $query", 'NOTICE');
 
        $dblink = get_db_link('write');
 
-       // Invalidate query cache
-       if ($DB_QUERY_CACHE) {
-               /* @var ElggStaticVariableCache $DB_QUERY_CACHE */
-               $DB_QUERY_CACHE->clear();
-               elgg_log("Query cache invalidated", 'NOTICE');
-       }
+       _elgg_invalidate_query_cache();
 
        if (execute_query("$query", $dblink)) {
                return mysql_affected_rows($dblink);
@@ -543,6 +524,19 @@ function delete_data($query) {
        return FALSE;
 }
 
+/**
+ * Invalidate the query cache
+ * 
+ * @access private
+ */
+function _elgg_invalidate_query_cache() {
+       global $DB_QUERY_CACHE;
+       if ($DB_QUERY_CACHE) {
+               /* @var ElggStaticVariableCache $DB_QUERY_CACHE */
+               $DB_QUERY_CACHE->clear();
+               elgg_log("Query cache invalidated", 'NOTICE');
+       }
+}
 
 /**
  * Return tables matching the database prefix {@link $CONFIG->dbprefix}% in the currently
index d684af862781f4bc2c3bcbe8cb7943c0ec94a660..0cc1e64dc45cb290596d697479d15a3847973d12 100644 (file)
@@ -354,16 +354,12 @@ function _elgg_upgrade_unlock() {
  * @access private
  */
 function _elgg_upgrade_is_locked() {
-       global $CONFIG, $DB_QUERY_CACHE;
-       
+       global $CONFIG;
+
        $is_locked = count(get_data("show tables like '{$CONFIG->dbprefix}upgrade_lock'"));
-       
-       // Invalidate query cache
-       if ($DB_QUERY_CACHE) {
-               /* @var ElggStaticVariableCache $DB_QUERY_CACHE */
-               $DB_QUERY_CACHE->clear();
-               elgg_log("Query cache invalidated", 'NOTICE');
-       }
-       
+
+       // @todo why?
+       _elgg_invalidate_query_cache();
+
        return $is_locked;
 }
index b91b99d959b19796c9aa1a9226302654d297d353..3ad113fb2888272f0bcded5d70ba2ce89e96151e 100644 (file)
@@ -203,14 +203,15 @@ function user_file_matrix($guid) {
        return "$time_created/$user->guid/";
 }
 
-global $DB_QUERY_CACHE, $ENTITY_CACHE, $CONFIG;
+global $ENTITY_CACHE, $CONFIG;
 /**
  * Upgrade file locations
  */
 $users = mysql_query("SELECT guid, username
        FROM {$CONFIG->dbprefix}users_entity WHERE username != ''");
 while ($user = mysql_fetch_object($users)) {
-       $DB_QUERY_CACHE = $ENTITY_CACHE = array();
+       $ENTITY_CACHE = array();
+       _elgg_invalidate_query_cache();
 
        $to = $CONFIG->dataroot . user_file_matrix($user->guid);
        foreach (array('1_0', '1_1', '1_6') as $version) {
index b23ad08207724abc2cc4f90e3faf39f3e42d10ca..744c28fd592b1df6885b755685c262e2dd3bdc3b 100644 (file)
@@ -45,7 +45,7 @@ if ($dbversion < 2009100701) {
                        }
                }
 
-               global $DB_QUERY_CACHE, $ENTITY_CACHE;
+               global $ENTITY_CACHE;
 
                /**
                        Upgrade file locations
@@ -60,7 +60,9 @@ if ($dbversion < 2009100701) {
                $users = mysql_query("SELECT guid, username FROM {$CONFIG->dbprefix}users_entity
                        WHERE username != ''", $link);
                while ($user = mysql_fetch_object($users)) {
-                       $DB_QUERY_CACHE = $ENTITY_CACHE = array();
+                       $ENTITY_CACHE = array();
+                       _elgg_invalidate_query_cache();
+
 
                        $to = $CONFIG->dataroot . user_file_matrix($user->guid);
                        foreach (array('1_0', '1_1', '1_6') as $version) {
index 34f5a773e7f40eea4f8a1d1668722da4ada5bcfd..5594493a8eb1d4341726e26f7611d3a6d76f329b 100644 (file)
@@ -30,11 +30,12 @@ function user_file_matrix_2010071001($guid) {
 
 $sizes = array('large', 'medium', 'small', 'tiny', 'master', 'topbar');
 
-global $DB_QUERY_CACHE, $ENTITY_CACHE, $CONFIG;
+global $ENTITY_CACHE, $CONFIG;
 $users = mysql_query("SELECT guid, username FROM {$CONFIG->dbprefix}users_entity
        WHERE username != ''");
 while ($user = mysql_fetch_object($users)) {
-       $DB_QUERY_CACHE = $ENTITY_CACHE = array();
+       $ENTITY_CACHE = array();
+       _elgg_invalidate_query_cache();
 
        $user_directory = user_file_matrix_2010071001($user->guid);
        if (!$user_directory) {
index d1c74ed48977d2f510cd1683f4e92c5012aa2d27..52aa15ef5b3a66ef7c9bef49036fd05b608a63c0 100644 (file)
@@ -4,12 +4,13 @@
  */
 
 // loop through all users checking collections and notifications
-global $DB_QUERY_CACHE, $ENTITY_CACHE, $CONFIG;
+global $ENTITY_CACHE, $CONFIG;
 global $NOTIFICATION_HANDLERS;
 $users = mysql_query("SELECT guid, username FROM {$CONFIG->dbprefix}users_entity
        WHERE username != ''");
 while ($user = mysql_fetch_object($users)) {
-       $DB_QUERY_CACHE = $ENTITY_CACHE = array();
+       $ENTITY_CACHE = array();
+       _elgg_invalidate_query_cache();
 
        $user = get_entity($user->guid);
        foreach ($NOTIFICATION_HANDLERS as $method => $foo) {
index d68e0118ef40f37646c09663fcbd50dba1333dda..b5a8e10188fcca760ebdf1f781ca65539c97ae04 100644 (file)
@@ -2,7 +2,7 @@
 /**
  * Make sure all users have the relationship member_of_site
  */
-global $DB_QUERY_CACHE, $ENTITY_CACHE;
+global $ENTITY_CACHE;
 $db_prefix = get_config('dbprefix');
 
 $limit = 100;
@@ -17,7 +17,8 @@ $q = "SELECT e.* FROM {$db_prefix}entities e
 $users = get_data($q);
 
 while ($users) {
-       $DB_QUERY_CACHE = $ENTITY_CACHE = array();
+       $ENTITY_CACHE = array();
+       _elgg_invalidate_query_cache();
 
        // do manually to not trigger any events because these aren't new users.
        foreach ($users as $user) {
index b38eb5100b2104da6d1b923312f1dfeef7685c84..8eccf05e2b2c30f4575e63d13803628bbb7895e0 100644 (file)
@@ -7,8 +7,6 @@
  * This script turns that back into a string.
  */
 
-global $DB_QUERY_CACHE;
-
 $ia = elgg_set_ignore_access(true);
 $options = array(
        'type' => 'user',
@@ -17,7 +15,7 @@ $options = array(
 $batch = new ElggBatch('elgg_get_entities', $options);
 
 foreach ($batch as $entity) {
-       $DB_QUERY_CACHE = array();
+       _elgg_invalidate_query_cache();
        
        if (is_array($entity->location)) {
                $entity->location = implode(', ', $entity->location);