]> gitweb.fluxo.info Git - lorea/elgg.git/commitdiff
cleanup of entity caching code
authorcash <cash.costello@gmail.com>
Sat, 13 Apr 2013 17:28:18 +0000 (13:28 -0400)
committercash <cash.costello@gmail.com>
Sat, 13 Apr 2013 17:28:18 +0000 (13:28 -0400)
engine/classes/ElggEntity.php
engine/classes/ElggGroup.php
engine/classes/ElggObject.php
engine/classes/ElggSite.php
engine/classes/ElggUser.php
engine/lib/entities.php
engine/lib/river.php
engine/lib/users.php
mod/pages/actions/pages/delete.php

index 5a63c7b151d2ffacda929ab9744c570a5da83e6f..8b3ceb5511809d608c5118a96e847cc4f7d553d6 100644 (file)
@@ -1270,7 +1270,7 @@ abstract class ElggEntity extends ElggData implements
        public function save() {
                $guid = $this->getGUID();
                if ($guid > 0) {
-                       cache_entity($this);
+                       _elgg_cache_entity($this);
 
                        return update_entity(
                                $guid,
@@ -1320,7 +1320,7 @@ abstract class ElggEntity extends ElggData implements
                        $this->attributes['subtype'] = get_subtype_id($this->attributes['type'],
                                $this->attributes['subtype']);
 
-                       cache_entity($this);
+                       _elgg_cache_entity($this);
 
                        return $this->attributes['guid'];
                }
@@ -1362,7 +1362,7 @@ abstract class ElggEntity extends ElggData implements
 
                        // Cache object handle
                        if ($this->attributes['guid']) {
-                               cache_entity($this);
+                               _elgg_cache_entity($this);
                        }
 
                        return true;
index 7ab0bfa48a968d1743a0353a350c531b15c8fefc..61f9163d5302a1032d37d2851912f22572c7d2f5 100644 (file)
@@ -335,7 +335,7 @@ class ElggGroup extends ElggEntity
 
                $this->attributes = $attrs;
                $this->attributes['tables_loaded'] = 2;
-               cache_entity($this);
+               _elgg_cache_entity($this);
 
                return true;
        }
index 3cb76ffaf067e114d4fc0ca89560a41c32cbd220..d54752dca5d32614f54f51638d54830ece976699 100644 (file)
@@ -107,7 +107,7 @@ class ElggObject extends ElggEntity {
 
                $this->attributes = $attrs;
                $this->attributes['tables_loaded'] = 2;
-               cache_entity($this);
+               _elgg_cache_entity($this);
 
                return true;
        }
index deba5087ec851cea35f9b5c6acc3311f04eb7b72..dd996fe9896b055c34e8456b0ed50ac77b49241c 100644 (file)
@@ -124,7 +124,7 @@ class ElggSite extends ElggEntity {
 
                $this->attributes = $attrs;
                $this->attributes['tables_loaded'] = 2;
-               cache_entity($this);
+               _elgg_cache_entity($this);
 
                return true;
        }
index b80065b272193b8223765d870e68e06fc6222da1..6d9f10b576a8747cfbde531358caf68fc9c1d956 100644 (file)
@@ -112,7 +112,7 @@ class ElggUser extends ElggEntity
 
                $this->attributes = $attrs;
                $this->attributes['tables_loaded'] = 2;
-               cache_entity($this);
+               _elgg_cache_entity($this);
 
                return true;
        }
index 156eec040f4a8bb335d5866e5ba60a1083eea948..cb972b282abd2ee3320533d1a936e9024790e14c 100644 (file)
@@ -30,10 +30,10 @@ $SUBTYPE_CACHE = null;
  *
  * @param int $guid The entity guid
  *
- * @return null
+ * @return void
  * @access private
  */
-function invalidate_cache_for_entity($guid) {
+function _elgg_invalidate_cache_for_entity($guid) {
        global $ENTITY_CACHE;
 
        $guid = (int)$guid;
@@ -50,13 +50,13 @@ function invalidate_cache_for_entity($guid) {
  *
  * @param ElggEntity $entity Entity to cache
  *
- * @return null
- * @see retrieve_cached_entity()
- * @see invalidate_cache_for_entity()
+ * @return void
+ * @see _elgg_retrieve_cached_entity()
+ * @see _elgg_invalidate_cache_for_entity()
  * @access private
- * TODO(evan): Use an ElggCache object
+ * @todo Use an ElggCache object
  */
-function cache_entity(ElggEntity $entity) {
+function _elgg_cache_entity(ElggEntity $entity) {
        global $ENTITY_CACHE;
 
        // Don't cache non-plugin entities while access control is off, otherwise they could be
@@ -66,7 +66,7 @@ function cache_entity(ElggEntity $entity) {
        }
 
        // Don't store too many or we'll have memory problems
-       // TODO(evan): Pick a less arbitrary limit
+       // @todo Pick a less arbitrary limit
        if (count($ENTITY_CACHE) > 256) {
                $random_guid = array_rand($ENTITY_CACHE);
 
@@ -88,11 +88,11 @@ function cache_entity(ElggEntity $entity) {
  * @param int $guid The guid
  *
  * @return ElggEntity|bool false if entity not cached, or not fully loaded
- * @see cache_entity()
- * @see invalidate_cache_for_entity()
+ * @see _elgg_cache_entity()
+ * @see _elgg_invalidate_cache_for_entity()
  * @access private
  */
-function retrieve_cached_entity($guid) {
+function _elgg_retrieve_cached_entity($guid) {
        global $ENTITY_CACHE;
 
        if (isset($ENTITY_CACHE[$guid])) {
@@ -104,31 +104,6 @@ function retrieve_cached_entity($guid) {
        return false;
 }
 
-/**
- * As retrieve_cached_entity, but returns the result as a stdClass
- * (compatible with load functions that expect a database row.)
- *
- * @param int $guid The guid
- *
- * @return mixed
- * @todo unused
- * @access private
- */
-function retrieve_cached_entity_row($guid) {
-       $obj = retrieve_cached_entity($guid);
-       if ($obj) {
-               $tmp = new stdClass;
-
-               foreach ($obj as $k => $v) {
-                       $tmp->$k = $v;
-               }
-
-               return $tmp;
-       }
-
-       return false;
-}
-
 /**
  * Return the id for a given subtype.
  *
@@ -745,7 +720,7 @@ function get_entity($guid) {
        }
        
        // Check local cache first
-       $new_entity = retrieve_cached_entity($guid);
+       $new_entity = _elgg_retrieve_cached_entity($guid);
        if ($new_entity) {
                return $new_entity;
        }
@@ -782,7 +757,7 @@ function get_entity($guid) {
        }
 
        if ($new_entity) {
-               cache_entity($new_entity);
+               _elgg_cache_entity($new_entity);
        }
        return $new_entity;
 }
@@ -1037,7 +1012,7 @@ function elgg_get_entities(array $options = array()) {
                        foreach ($dt as $item) {
                                // A custom callback could result in items that aren't ElggEntity's, so check for them
                                if ($item instanceof ElggEntity) {
-                                       cache_entity($item);
+                                       _elgg_cache_entity($item);
                                        // plugins usually have only settings
                                        if (!$item instanceof ElggPlugin) {
                                                $guids[] = $item->guid;
@@ -1102,7 +1077,7 @@ function _elgg_fetch_entities_from_sql($sql) {
                if (empty($row->guid) || empty($row->type)) {
                        throw new LogicException('Entity row missing guid or type');
                }
-               if ($entity = retrieve_cached_entity($row->guid)) {
+               if ($entity = _elgg_retrieve_cached_entity($row->guid)) {
                        $rows[$i] = $entity;
                        continue;
                }
@@ -1628,7 +1603,7 @@ function disable_entity($guid, $reason = "", $recursive = true) {
 
                                $entity->disableMetadata();
                                $entity->disableAnnotations();
-                               invalidate_cache_for_entity($guid);
+                               _elgg_invalidate_cache_for_entity($guid);
 
                                $res = update_data("UPDATE {$CONFIG->dbprefix}entities
                                        SET enabled = 'no'
@@ -1726,7 +1701,7 @@ function delete_entity($guid, $recursive = true) {
 
                                // delete cache
                                if (isset($ENTITY_CACHE[$guid])) {
-                                       invalidate_cache_for_entity($guid);
+                                       _elgg_invalidate_cache_for_entity($guid);
                                }
                                
                                // If memcache is available then delete this entry from the cache
index f2ec1e101ae954999386ca28cee353cde6c2113d..4926a85c47723f1dddd85bf1c55866ea401c92fb 100644 (file)
@@ -380,10 +380,10 @@ function _elgg_prefetch_river_entities(array $river_items) {
        // prefetch objects and subjects
        $guids = array();
        foreach ($river_items as $item) {
-               if ($item->subject_guid && !retrieve_cached_entity($item->subject_guid)) {
+               if ($item->subject_guid && !_elgg_retrieve_cached_entity($item->subject_guid)) {
                        $guids[$item->subject_guid] = true;
                }
-               if ($item->object_guid && !retrieve_cached_entity($item->object_guid)) {
+               if ($item->object_guid && !_elgg_retrieve_cached_entity($item->object_guid)) {
                        $guids[$item->object_guid] = true;
                }
        }
@@ -402,7 +402,7 @@ function _elgg_prefetch_river_entities(array $river_items) {
        $guids = array();
        foreach ($river_items as $item) {
                $object = $item->getObjectEntity();
-               if ($object->container_guid && !retrieve_cached_entity($object->container_guid)) {
+               if ($object->container_guid && !_elgg_retrieve_cached_entity($object->container_guid)) {
                        $guids[$object->container_guid] = true;
                }
        }
index 4a585c07f2a60c5dd08dd75cc5eb3d0cf8ca1200..868cd78153e69d173bdcf58ca1daf0da5213c827 100644 (file)
@@ -237,7 +237,7 @@ function make_user_admin($user_guid) {
                        }
 
                        $r = update_data("UPDATE {$CONFIG->dbprefix}users_entity set admin='yes' where guid=$user_guid");
-                       invalidate_cache_for_entity($user_guid);
+                       _elgg_invalidate_cache_for_entity($user_guid);
                        return $r;
                }
 
@@ -273,7 +273,7 @@ function remove_user_admin($user_guid) {
                        }
 
                        $r = update_data("UPDATE {$CONFIG->dbprefix}users_entity set admin='no' where guid=$user_guid");
-                       invalidate_cache_for_entity($user_guid);
+                       _elgg_invalidate_cache_for_entity($user_guid);
                        return $r;
                }
 
@@ -558,8 +558,8 @@ function get_user_by_username($username) {
 
        // Caching
        if ((isset($USERNAME_TO_GUID_MAP_CACHE[$username]))
-                       && (retrieve_cached_entity($USERNAME_TO_GUID_MAP_CACHE[$username]))) {
-               return retrieve_cached_entity($USERNAME_TO_GUID_MAP_CACHE[$username]);
+                       && (_elgg_retrieve_cached_entity($USERNAME_TO_GUID_MAP_CACHE[$username]))) {
+               return _elgg_retrieve_cached_entity($USERNAME_TO_GUID_MAP_CACHE[$username]);
        }
 
        $query = "SELECT e.* from {$CONFIG->dbprefix}users_entity u
@@ -592,9 +592,9 @@ function get_user_by_code($code) {
 
        // Caching
        if ((isset($CODE_TO_GUID_MAP_CACHE[$code]))
-       && (retrieve_cached_entity($CODE_TO_GUID_MAP_CACHE[$code]))) {
+       && (_elgg_retrieve_cached_entity($CODE_TO_GUID_MAP_CACHE[$code]))) {
 
-               return retrieve_cached_entity($CODE_TO_GUID_MAP_CACHE[$code]);
+               return _elgg_retrieve_cached_entity($CODE_TO_GUID_MAP_CACHE[$code]);
        }
 
        $query = "SELECT e.* from {$CONFIG->dbprefix}users_entity u
index c99f15fbf5bb99a863a4e6555a95f3e1f09abbca..fd5791e4dcf6c4405aef83640d5d3eedb7889cc3 100644 (file)
@@ -40,7 +40,7 @@ if (elgg_instanceof($page, 'object', 'page') || elgg_instanceof($page, 'object',
                                                'metadata_name' => 'parent_guid',
                                        ));
 
-                                       invalidate_cache_for_entity($child_guid);
+                                       _elgg_invalidate_cache_for_entity($child_guid);
                                        if ($newentity_cache) {
                                                $newentity_cache->delete($child_guid);
                                        }