Skip to content

Commit

Permalink
Convert some database queries.
Browse files Browse the repository at this point in the history
  • Loading branch information
bharat committed Dec 18, 2009
1 parent 8883d16 commit 9d19e27
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 18 deletions.
25 changes: 12 additions & 13 deletions modules/gallery/helpers/gallery_event.php
Expand Up @@ -49,19 +49,18 @@ static function user_deleted($user) {

static function identity_provider_changed($old_provider, $new_provider) {
$admin = identity::admin_user();
$db = Database::instance();
$db->from("tasks")
->set(array("owner_id" => $admin->id))
->where("1", "=", "1") // @todo why do we need this?
->update();
$db->from("items")
->set(array("owner_id" => $admin->id))
->where("1", "=", "1") // @todo why do we need this?
->update();
$db->from("logs")
->set(array("user_id" => $admin->id))
->where("1", "=", "1") // @todo why do we need this?
->update();
db::build()
->update("tasks")
->set("owner_id", $admin->id)
->execute();
db::build()
->update("items")
->set("owner_id", $admin->id)
->execute();
db::build()
->update("logs")
->set("user_id", $admin->id)
->execute();
}

static function group_created($group) {
Expand Down
23 changes: 18 additions & 5 deletions modules/gallery/helpers/module.php
Expand Up @@ -432,17 +432,30 @@ static function set_var($module_name, $name, $value) {

/**
* Increment the value of a variable for this module
*
* Note: Frequently updating counters is very inefficient because it invalidates the cache value
* which has to be rebuilt every time we make a change.
*
* @todo Get rid of this and find an alternate approach for all callers (currently only Akismet)
*
* @deprecated
* @param string $module_name
* @param string $name
* @param string $increment (optional, default is 1)
*/
static function incr_var($module_name, $name, $increment=1) {
Database::instance()->query(
"UPDATE {vars} SET `value` = `value` + $increment " .
"WHERE `module_name` = '$module_name' " .
"AND `name` = '$name'");
db::build()
->update("vars")
->set("value", new Database_Expression("`value` + $increment"))
->where("module_name", "=", $module_name)
->where("name", "=", $name)
->execute();

Database::instance()->delete("vars", array("module_name" => "gallery", "name" => "_cache"));
db::build()
->delete("vars")
->where("module_name", "=", "gallery")
->where("name", "=", "_cache")
->execute();
self::$var_cache = null;
}

Expand Down

0 comments on commit 9d19e27

Please sign in to comment.