From 72a23a6b2bae1cf907484b435987dce0c16e66f0 Mon Sep 17 00:00:00 2001 From: icewing Date: Mon, 9 Jun 2008 16:30:26 +0000 Subject: Marcus Povey * Added table counter git-svn-id: https://code.elgg.org/elgg/trunk@837 36083f99-b078-4883-b0ff-0f9b5a30f544 --- engine/lib/entities.php | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) (limited to 'engine/lib/entities.php') diff --git a/engine/lib/entities.php b/engine/lib/entities.php index cbcd5ccad..7e1bd8ab7 100644 --- a/engine/lib/entities.php +++ b/engine/lib/entities.php @@ -65,6 +65,20 @@ $this->attributes['access_id'] = 0; $this->attributes['time_created'] = ""; $this->attributes['time_updated'] = ""; + + // There now follows a bit of a hack + /* Problem: To speed things up, some objects are split over several tables, this means that it requires + * n number of database reads to fully populate an entity. This causes problems for caching and create events + * since it is not possible to tell whether a subclassed entity is complete. + * Solution: We have two counters, one 'tables_split' which tells whatever is interested how many tables + * are going to need to be searched in order to fully populate this object, and 'tables_loaded' which is how + * many have been loaded thus far. + * If the two are the same then this object is complete. + * + * Use: isFullyLoaded() to check + */ + $this->attributes['tables_split'] = 1; + $this->attributes['tables_loaded'] = 0; } /** @@ -390,6 +404,13 @@ */ public function getURL() { return get_entity_url($this->getGUID()); } + /** + * Tests to see whether the object has been fully loaded. + * + * @return bool + */ + public function isFullyLoaded() { return $this->attributes['tables_split'] == $this->attributes['tables_loaded']; } + /** * Save generic attributes to the entities table. */ @@ -445,6 +466,9 @@ foreach($objarray as $key => $value) $this->attributes[$key] = $value; + // Increment the portion counter + $this->attributes['tables_loaded'] ++; + // Cache object handle if ($this->attributes['guid']) cache_entity($this); @@ -499,6 +523,9 @@ case 'type' : // Don't use type case 'access_id' : // Don't use access - if can export then its public for you, then importer decides what access to give this object. case 'time_updated' : // Don't use date in export + + case 'tables_split' : // We don't want to export the internal counter variables. + case 'tables_loaded' : // Or this one break; case 'time_created' : // Created = published -- cgit v1.2.3