diff options
author | Karl 'vollmerk' Vollmer <vollmer@ampache.org> | 2009-02-19 17:04:08 +0000 |
---|---|---|
committer | Karl 'vollmerk' Vollmer <vollmer@ampache.org> | 2009-02-19 17:04:08 +0000 |
commit | a0975517e17913cf2a72901144aad8966c37ad86 (patch) | |
tree | 876491f49db1fb72cb88c731e452a3e38f6cdbf3 /lib/class/flag.class.php | |
parent | 847ec135fd91c8529262afac2a3b7f82d31a7fcd (diff) | |
download | ampache-a0975517e17913cf2a72901144aad8966c37ad86.tar.gz ampache-a0975517e17913cf2a72901144aad8966c37ad86.tar.bz2 ampache-a0975517e17913cf2a72901144aad8966c37ad86.zip |
failed attempt to implement flag caching, commiting so I can work on it later
Diffstat (limited to 'lib/class/flag.class.php')
-rw-r--r-- | lib/class/flag.class.php | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/lib/class/flag.class.php b/lib/class/flag.class.php index 797fde76..148d5aa8 100644 --- a/lib/class/flag.class.php +++ b/lib/class/flag.class.php @@ -62,6 +62,8 @@ class Flag extends database_object { */ public static function build_cache($ids) { + if (!is_array($ids) OR !count($ids)) { return false; } + $idlist = '(' . implode(',',$ids) . ')'; $sql = "SELECT * FROM `flagged` WHERE `id` IN $idlist"; @@ -74,6 +76,54 @@ class Flag extends database_object { } // build_cache /** + * build_map_cache + * This takes an array of ids and builds a map cache to avoid some of the object_type calls + * we would normally have to make + */ + public static function build_map_cache($ids,$type) { + + if (!is_array($ids) OR !count($ids)) { return false; } + + $idlist = '(' . implode(',',$ids) . ')'; + $type = Dba::escape($type); + + $sql = "SELECT * FROM `flagged` " . + "WHERE `flagged`.`object_type`='$type' AND `flagged`.`object_id` IN $idlist"; + $db_results = Dba::read($sql); + + while ($row = Dba::fetch_assoc($db_results)) { + parent::add_to_cache('flagged_' . $type,$row['object_id'],$row); + } + + return true; + + } // build_map_cache + + /** + * has_flag + * Static function, tries to check the cache, but falls back on a query + */ + public static function has_flag($id,$type) { + + if (parent::is_cached('flagged_' . $type,$id)) { + $data = parent::get_from_cache('flagged_' . $type,$id); + return $data['date']; + } + + // Ok we have to query this + $type = Dba::escape($type); + + $sql = "SELECT * FROM `flagged` WHERE `flagged`.`object_type`='$type' AND `flagged`.`object_id`='$id'"; + $db_results = Dba::read($sql); + + $row = Dba::fetch_assoc($db_results); + parent::add_to_cache('flagged_' . $type,$row['object_id'],$row); + + return $row['date']; + + } // has_flag + + /** * get_recent * This returns the id's of the most recently flagged songs, it takes an int * as an argument which is the count of the object you want to return |