Permalink
Browse files

Merge branch 'master' into 3.0.x

  • Loading branch information...
2 parents 5cd8464 + 3e117fc commit d50e541f7b229c0584972899048d862f8dc858ec @bharat bharat committed Dec 29, 2010
View
@@ -43,7 +43,7 @@ CREATE TABLE {caches} (
`expiration` int(9) NOT NULL,
`cache` longblob,
PRIMARY KEY (`id`),
- KEY `key` (`key`),
+ UNIQUE KEY `key` (`key`),
KEY `tags` (`tags`)
) DEFAULT CHARSET=utf8;
/*!40101 SET character_set_client = @saved_cs_client */;
@@ -309,7 +309,7 @@ static function install() {
module::set_var("gallery", "show_user_profiles_to", "registered_users");
module::set_var("gallery", "extra_binary_paths", "/usr/local/bin:/opt/local/bin:/opt/bin");
- module::set_version("gallery", 41);
+ module::set_version("gallery", 42);
}
static function upgrade($version) {
@@ -642,6 +642,12 @@ static function upgrade($version) {
module::clear_var("gallery", "_cache");
module::set_version("gallery", $version = 41);
}
+
+ if ($version == 41) {
+ $db->query("TRUNCATE TABLE {caches}");
+ $db->query("ALTER TABLE {caches} DROP INDEX `key`, ADD UNIQUE `key` (`key`)");
+ module::set_version("gallery", $version = 42);
+ }
}
static function uninstall() {
@@ -25,20 +25,6 @@ class Cache_Database_Driver extends Cache_Driver {
protected $db;
/**
- * Checks if a cache id is already set.
- *
- * @param string cache id
- * @return boolean
- */
- public function exists($id) {
- $count = db::build()
- ->where("key", "=", $id)
- ->where("expiration", ">=", time())
- ->count_records("caches");
- return $count > 0;
- }
-
- /**
* Sets a cache item to the given data, tags, and lifetime.
*
* @param array assoc array of key => value pairs
@@ -59,22 +45,15 @@ public function set($items, $tags=null, $lifetime=null) {
$lifetime += time();
}
+ $db = Database::instance();
+ $tags = $db->escape($tags);
foreach ($items as $id => $data) {
- if ($this->exists($id)) {
- $status = db::build()
- ->update("caches")
- ->set("tags", $tags)
- ->set("expiration", $lifetime)
- ->set("cache", serialize($data))
- ->where("key", "=", $id)
- ->execute();
- } else {
- $status = db::build()
- ->insert("caches")
- ->columns("key", "tags", "expiration", "cache")
- ->values($id, $tags, $lifetime, serialize($data))
- ->execute();
- }
+ $id = $db->escape($id);
+ $data = $db->escape(serialize($data));
+ $db->query("INSERT INTO {caches} (`key`, `tags`, `expiration`, `cache`)
+ VALUES ('$id', '$tags', $lifetime, '$data')
+ ON DUPLICATE KEY UPDATE `tags` = VALUES(tags), `expiration` = VALUES(expiration),
+ `cache` = VALUES(cache)");
}
return true;
@@ -1,3 +1,3 @@
name = "Gallery 3"
description = "Gallery core application"
-version = 41
+version = 42
@@ -8,7 +8,7 @@
multiple: true,
multipleSeparator: ',',
cacheLength: 1,
- selectFirst: false,
+ selectFirst: false
}
);
$("#g-add-tag-form").ajaxForm({

0 comments on commit d50e541

Please sign in to comment.