summaryrefslogtreecommitdiff
path: root/modules/gallery/helpers/module.php
diff options
context:
space:
mode:
authorBharat Mediratta <bharat@menalto.com>2010-09-29 20:47:43 -0700
committerBharat Mediratta <bharat@menalto.com>2010-09-29 20:47:43 -0700
commitf84782d6200efb424731c93bd029c7cbeb9f3dad (patch)
tree1fea5d8c18a02a2a7e1cab901676bc4631b06df5 /modules/gallery/helpers/module.php
parentef8751468b998baddbc6d5827a392ed6e12e5548 (diff)
Stop caching all module variables in the vars table using the
name=_cache row. If that overflows, it will cause us to be unable to load variables, and we can't recover from that. Instead, use the Cache table. Bump the gallery module to v40. Fixes ticket #1405.
Diffstat (limited to 'modules/gallery/helpers/module.php')
-rw-r--r--modules/gallery/helpers/module.php55
1 files changed, 8 insertions, 47 deletions
diff --git a/modules/gallery/helpers/module.php b/modules/gallery/helpers/module.php
index 7863520e..64d0d1d6 100644
--- a/modules/gallery/helpers/module.php
+++ b/modules/gallery/helpers/module.php
@@ -425,48 +425,21 @@ class module_Core {
* @return the value
*/
static function get_var($module_name, $name, $default_value=null) {
- // We cache all vars in gallery._cache so that we can load all vars at once for
- // performance.
+ // We cache vars so we can load them all at once for performance.
if (empty(self::$var_cache)) {
- $row = db::build()
- ->select("value")
- ->from("vars")
- ->where("module_name", "=", "gallery")
- ->where("name", "=", "_cache")
- ->execute()
- ->current();
- if ($row) {
- self::$var_cache = unserialize($row->value);
- } else {
- // gallery._cache doesn't exist. Create it now.
+ self::$var_cache = Cache::instance()->get("var_cache");
+ if (empty(self::$var_cache)) {
+ // Cache doesn't exist, create it now.
foreach (db::build()
->select("module_name", "name", "value")
->from("vars")
->order_by("module_name")
->order_by("name")
->execute() as $row) {
- if ($row->module_name == "gallery" && $row->name == "_cache") {
- // This could happen if there's a race condition
- continue;
- }
// Mute the "Creating default object from empty value" warning below
@self::$var_cache->{$row->module_name}->{$row->name} = $row->value;
}
- $cache = ORM::factory("var");
- $cache->module_name = "gallery";
- $cache->name = "_cache";
- $cache->value = serialize(self::$var_cache);
- try {
- $cache->save();
- } catch (Database_Exception $e) {
- // There's a potential race condition here. Don't fail if that happens because it's
- // bound to be transient and not a huge deal, but at least put something in the logs.
- if (stristr($e->getMessage(), "duplicate entry")) {
- Kohana_Log::add("error", "Failed to cache vars");
- } else {
- throw $e;
- }
- }
+ Cache::instance()->set("var_cache", self::$var_cache, array("vars"));
}
}
@@ -495,11 +468,7 @@ class module_Core {
$var->value = $value;
$var->save();
- db::build()
- ->delete("vars")
- ->where("module_name", "=", "gallery")
- ->where("name", "=", "_cache")
- ->execute();
+ Cache::instance()->delete("var_cache");
self::$var_cache = null;
}
@@ -524,11 +493,7 @@ class module_Core {
->where("name", "=", $name)
->execute();
- db::build()
- ->delete("vars")
- ->where("module_name", "=", "gallery")
- ->where("name", "=", "_cache")
- ->execute();
+ Cache::instance()->delete("var_cache");
self::$var_cache = null;
}
@@ -546,11 +511,7 @@ class module_Core {
$var->delete();
}
- db::build()
- ->delete("vars")
- ->where("module_name", "=", "gallery")
- ->where("name", "=", "_cache")
- ->execute();
+ Cache::instance()->delete("var_cache");
self::$var_cache = null;
}