Changeset 1085


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

Location:
trunk
Files:
6 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 
  • trunk/config.php.sample

    r987 r1085  
    129129define("IA_MEM_CACHE_TASK_EXPIRATION", 10); 
    130130 
     131// TTL for tag caches. 
     132define("IA_MEM_CACHE_TAGS_EXPIRATION", 600); 
     133 
    131134// Logging options. Anything else in normal operation is a bug. 
    132135// Filling error_log on a production machine sucks. 
  • trunk/scripts/migrate-authors-to-task-tags

    r1084 r1085  
    99$tasks = task_get_all(); 
    1010$author_tags = array(); 
    11 foreach($tasks as $task) { 
     11foreach($tasks as &$task) { 
    1212    // Special cases to make my life easier. 
    1313    if ($task["author"] == "") { 
  • trunk/www/controllers/task_tags.php

    r1083 r1085  
    1717    } 
    1818 
     19    $authors = tag_get_all(array("author")); 
     20    foreach ($authors as &$author) { 
     21        $author["task_count"] = tag_count_objects("task", array($author["id"])); 
     22    } 
     23 
    1924    // Create view. 
    2025    $view = array(); 
    2126    $view['title'] = "Tag-uri probleme"; 
    2227    $view['categories'] = $categories; 
     28    $view['authors'] = $authors; 
    2329    execute_view_die("views/task_tags.php", $view); 
    2430} 
     
    7379 
    7480    // Do not delete tags if they have been added to tasks. 
    75     if ($tag["type"] == "algorithm") { 
    76         $task_count = tag_count_objects("task", array($tag_id)); 
    77     } else if ($tag["type"] == "method") { 
    78         $task_count = 0; 
    79         $sub_tags = tag_get_all(array("algorithm"), $tag_id); 
    80         foreach ($sub_tags as $sub_tag) { 
    81             $task_count += tag_count_objects("task", array($sub_tag["id"])); 
    82         } 
    83     } 
     81    $task_count = tag_count_objects("task", array($tag_id), true); 
    8482    if ($task_count != 0) { 
    8583        flash_error("Nu poti sterge un tag care a fost asociat deja unei probleme."); 
     
    116114 
    117115    $tag["name"] = $new_name; 
     116    if (tag_get_id($tag)) { 
     117        flash_error("Tagul deja exista."); 
     118        redirect(url_task_tags()); 
     119    } 
    118120    tag_update_by_id($tag_id, $tag); 
    119121    flash("Tag-ul a fost redenumit."); 
  • trunk/www/static/js/inline_form.js

    r1083 r1085  
    1111            // Display inline form and replace toggleElement with "Anuleaza" 
    1212            formElement.style.display = "inline"; 
    13             toggleElement.innerHTML = "Anuleaza"; 
     13            toggleElement.innerHTML = "Anulează"; 
    1414            // Hide original content if specified 
    1515            if (typeof(originalElement) != "undefined") { 
  • trunk/www/views/task_tags.php

    r1083 r1085  
    99    $tag = inline_post_form(url_task_tags_rename(), 
    1010        array( 
    11             "type" => "algorithm", 
    1211            "old_name" => $row["name"], 
     12            "type" => $row["type"], 
    1313            "parent" => $row["parent"] 
    1414        ), 
    15         $row["name"], "Redenumeste"); 
     15        $row["name"], "Redenumește"); 
    1616    $tag .= ' <a class="algorithm_tag" href="#">' . html_escape($row["name"]) . '</a>'; 
    1717    return $tag; 
     
    2020// Returns a delete tag link and a toggle rename form link 
    2121function format_operations($row) { 
    22     $delete = format_post_link(url_task_tags_delete(), "Sterge", 
     22    $delete = format_post_link(url_task_tags_delete(), "Șterge", 
    2323        array( 
     24            "name" => $row["name"], 
    2425            "type" => $row["type"], 
    25             "name" => $row["name"], 
    2626            "parent" => $row["parent"] 
    2727        ) 
    2828    ); 
    29     $rename = '<a href="#" class="toggle_rename">Redenumeste</a>'; 
     29    $rename = '<a href="#" class="toggle_rename">Redenumește</a>'; 
    3030    return sprintf("[%s] [%s]", $delete, $rename); 
    3131} 
     
    5050    ), 
    5151    array( 
    52         'title' => 'Numar probleme', 
     52        'title' => 'Număr probleme', 
    5353        'key' => 'task_count', 
    5454        'css_class' => 'tag-task-count', 
    5555    ), 
    5656    array( 
    57         'title' => 'Operatii', 
     57        'title' => 'Operații', 
    5858        'rowform' => 'format_operations', 
    5959        'css_class' => 'tag-operations', 
     
    6565<h1>Editare taguri algoritmi</h1> 
    6666<div id="add_category" class="task-tag-actions"> 
    67 [<a href="#">Adauga categorie noua</a><?php 
    68     echo inline_post_form(url_task_tags_add(), array("type" => "method"), "", "Adauga"); 
     67[<a href="#">Adaugă categorie nouă</a><?php 
     68    echo inline_post_form(url_task_tags_add(), array("type" => "method"), "", "Adaugă"); 
    6969?>] 
    7070</div> 
     
    7474    <h2><?php echo html_escape($category["name"]); ?></h2> 
    7575    <ul class="task-tag-actions"> 
    76         <li class="algorithm_tag_add">[<a class="toggle_add" href="#">Adauga tag nou</a><?php 
     76        <li class="algorithm_tag_add">[<a class="toggle_add" href="#">Adaugă tag nou</a><?php 
    7777            echo inline_post_form(url_task_tags_add(), 
    7878                array("type" => "algorithm", "parent" => $category["id"]), 
    79                 "", "Adauga"); 
     79                "", "Adaugă"); 
    8080        ?>]</li> 
    81         <li class="delete_method">[<?php echo format_post_link(url_task_tags_delete(), "Sterge categorie", 
     81        <li class="delete_method">[<?php echo format_post_link(url_task_tags_delete(), "Șterge categorie", 
    8282            array("type" => "method", "name" => $category["name"])); ?>]</li> 
    83         <li class="rename_method">[<a class="toggle_rename" href="#">Redenumeste categorie</a><?php 
     83        <li class="rename_method">[<a class="toggle_rename" href="#">Redenumește categorie</a><?php 
    8484            echo inline_post_form(url_task_tags_rename(), 
    8585                array("type" => "method", "old_name" => $category["name"]), 
    86                 $category["name"], "Redenumeste"); 
     86                $category["name"], "Redenumește"); 
    8787        ?>]</li> 
    8888    </ul> 
     
    9494} 
    9595?> 
     96<h1>Editare taguri autori</h1> 
     97<div id="add_author" class="task-tag-actions">[<a class="toggle_add" href="#">Adaugă tag nou</a><?php 
     98    echo inline_post_form(url_task_tags_add(), 
     99        array("type" => "author"), 
     100        "", "Adaugă"); 
     101?>]</div> 
     102<?php 
     103echo format_table($authors, $column_infos, 
     104    array('css_class' => 'category fill-screen tag-table')); 
     105?> 
    96106<script type="text/javascript" src="<?= html_escape(url_static('js/inline_form.js')) ?>"></script> 
    97107<script type="text/javascript"> 
     
    100110addLoadEvent(function() { 
    101111    bindToggleLinkToForm($$("#add_category > a")[0], $$("#add_category > form")[0]); 
     112}); 
     113 
     114// Bind add author link to form 
     115addLoadEvent(function() { 
     116    bindToggleLinkToForm($$("#add_author > a")[0], $$("#add_author > form")[0]); 
    102117}); 
    103118 
Note: See TracChangeset for help on using the changeset viewer.