Changeset 1085 for trunk/common


Ignore:
Timestamp:
12/22/09 14:06:43 (2 years ago)
Author:
bogdan2412
Message:

Add author tags to admin task tags interface.

Adds caching for tagged object count for single tags.

REVIEW URL: http://reviewboard.infoarena.ro/r/125

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/common/db/tags.php

    r1084 r1085  
    33require_once(IA_ROOT_DIR."common/db/db.php"); 
    44require_once(IA_ROOT_DIR."common/common.php"); 
     5require_once(IA_ROOT_DIR."common/cache.php"); 
    56 
    67// Get list of all tag names, filtered by type and parent 
     
    183184 
    184185// Count the number of objects containing all tags from a list of tag ids 
    185 function tag_count_objects($obj, $tag_ids) { 
     186function tag_count_objects($obj, $tag_ids, $no_cache=false) { 
    186187    log_assert(is_taggable($obj)); 
    187188    log_assert(is_array($tag_ids)); 
     189    // Cache object count for single tags. 
     190    if (!$no_cache && count($tag_ids) == 1) { 
     191        $result = mem_cache_get("$obj-count-with-tag:".$tag_ids[0]); 
     192        if ($result !== false) { 
     193            return $result; 
     194        } 
     195    } 
    188196    $query = sprintf("SELECT COUNT(*) as `cnt` FROM ia_%s WHERE %s", db_escape($obj), 
    189197                     tag_build_where($obj, $tag_ids)); 
    190198    $result = db_fetch($query); 
    191     return $result['cnt']; 
     199    $result = $result['cnt']; 
     200    if (count($tag_ids) == 1) { 
     201        mem_cache_set("$obj-count-with-tag:".$tag_ids[0], $result, 
     202            IA_MEM_CACHE_TAGS_EXPIRATION); 
     203    } 
     204    return $result; 
    192205} 
    193206 
Note: See TracChangeset for help on using the changeset viewer.