summaryrefslogtreecommitdiffstats
path: root/lib/class/tag.class.php
diff options
context:
space:
mode:
authorKarl 'vollmerk' Vollmer <vollmer@ampache.org>2008-05-26 22:07:26 +0000
committerKarl 'vollmerk' Vollmer <vollmer@ampache.org>2008-05-26 22:07:26 +0000
commit5fce261ae2a1fad5a6f1e437a5245a7b1bf981f3 (patch)
treea7607908104b23e84c4793a0da1a4c79a11258f9 /lib/class/tag.class.php
parentfdc509c5c4e2e2256585889ccf0a11a1712f1316 (diff)
downloadampache-5fce261ae2a1fad5a6f1e437a5245a7b1bf981f3.tar.gz
ampache-5fce261ae2a1fad5a6f1e437a5245a7b1bf981f3.tar.bz2
ampache-5fce261ae2a1fad5a6f1e437a5245a7b1bf981f3.zip
more improvements to the caching system, removed ugly hack from last night on util
Diffstat (limited to 'lib/class/tag.class.php')
-rw-r--r--lib/class/tag.class.php37
1 files changed, 36 insertions, 1 deletions
diff --git a/lib/class/tag.class.php b/lib/class/tag.class.php
index ff0bfa9c..3499cd94 100644
--- a/lib/class/tag.class.php
+++ b/lib/class/tag.class.php
@@ -110,9 +110,39 @@ class Tag extends database_object {
parent::add_to_cache('tag',$row['id'],$row);
}
+ return true;
+
} // build_cache
/**
+ * build_map_cache
+ * This builds a cache of the mappings for the specified object, no limit is given
+ */
+ public static function build_map_cache($type,$ids) {
+
+ $type = self::validate_type($type);
+ $idlist = '(' . implode(',',$ids) . ')';
+
+ $sql = "SELECT COUNT(`tag_map`.`id`) AS `count`,`tag`.`id`,`tag_map`.`object_id` FROM `tag_map` " .
+ "INNER JOIN `tag` ON `tag`.`id`=`tag_map`.`tag_id` " .
+ "WHERE `tag_map`.`object_type`='$type' AND `tag_map`.`object_id` IN $idlist " .
+ "GROUP BY `tag_map`.`object_id` ORDER BY `count` DESC";
+ $db_results = Dba::query($sql);
+
+ while ($row = Dba::fetch_assoc($db_results)) {
+ $tags[$row['object_id']][] = $row;
+ }
+
+
+ foreach ($tags as $id=>$entry) {
+ parent::add_to_cache('tag_map_' . $type,$id,$entry);
+ }
+
+ return true;
+
+ } // build_map_cache
+
+ /**
* has_object
* This checks to see if the current tag element has the specified object
* of the specified type
@@ -249,13 +279,18 @@ return array();
public static function get_top_tags($type,$object_id,$limit='2') {
$type = self::validate_type($type);
+
+ if (parent::is_cached('tag_map_' . $type,$object_id)) {
+ return parent::get_from_cache('tag_map_' . $type,$object_id);
+ }
+
$object_id = intval($object_id);
$limit = intval($limit);
$sql = "SELECT COUNT(`tag_map`.`id`) AS `count`,`tag`.`id` FROM `tag_map` " .
"INNER JOIN `tag` ON `tag`.`id`=`tag_map`.`tag_id` " .
"WHERE `tag_map`.`object_type`='$type' AND `tag_map`.`object_id`='$object_id' " .
- "GROUP BY `tag_map`.`tag_id` ORDER BY `count` LIMIT $limit";
+ "GROUP BY `tag_map`.`object_id` ORDER BY `count` DESC LIMIT $limit";
$db_results = Dba::query($sql);
$results = array();