Changeset 965


Ignore:
Timestamp:
11/23/08 16:19:59 (3 years ago)
Author:
bogdan2412
Message:

Make it possible for disk cache to handle more complex paths for files (for example to put all files beginning with ab in cache/a/ab/)
Since I don't know how we can benchmark this properly the default behaiviour is still the same as before (all cache files are put in IA_ROOT_DIR/cache/)

Also, I added a few fixes from live.

Location:
trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/common/cache.php

    r852 r965  
    77// 
    88// Only returns true/false. 
     9 
     10// Used internally to determine file path from cache_id 
     11function _disk_cache_path($cache_id) { 
     12    return IA_ROOT_DIR . "cache/" . $cache_id; 
     13} 
     14 
     15// Recursively delete directories 
     16function _recursive_delete($path) { 
     17    foreach (glob($path . "/*") as $file_name) { 
     18        if (is_dir($file_name)) { 
     19            _recursive_delete($file_name); 
     20        } else if (is_file($file_name)) { 
     21            unlink($file_name); 
     22        } 
     23    } 
     24    rmdir($path); 
     25} 
     26 
    927function disk_cache_has($cache_id, $date = null) { 
    10     $file_name = IA_ROOT_DIR . 'cache/' . $cache_id; 
     28    $file_name = _disk_cache_path($cache_id); 
    1129 
    1230    if (!@is_readable($file_name)) { 
     
    3250// Get an object from the cache, or FALSE if nothing is found. 
    3351function disk_cache_get($cache_id) { 
    34     $file_name = IA_ROOT_DIR . 'cache/' . $cache_id; 
     52    $file_name = _disk_cache_path($cache_id); 
    3553 
    3654    if (@is_readable($file_name)) { 
     
    5169function disk_cache_serve($cache_id, $http_file_name, $mime_type = null) { 
    5270    require_once(IA_ROOT_DIR . 'www/utilities.php'); 
    53     $file_name = IA_ROOT_DIR . 'cache/' . $cache_id; 
     71    $file_name = _disk_cache_path($cache_id); 
    5472 
    5573    if (IA_LOG_DISK_CACHE) { 
     
    6381// Always returns $buffer. 
    6482function disk_cache_set($cache_id, $buffer, $ttl = 0) { 
    65     $file_name = IA_ROOT_DIR . 'cache/' . $cache_id; 
    66  
     83    $file_name = _disk_cache_path($cache_id); 
     84 
     85    @mkdir(dirname($file_name), 0777, true); 
    6786    $ret = @file_put_contents($file_name, $buffer, LOCK_EX); 
    6887 
     
    8099// Delete something from the disk cache. 
    81100function disk_cache_delete($cache_id) { 
    82     $file_name = IA_ROOT_DIR . 'cache/' . $cache_id; 
     101    $file_name = _disk_cache_path($cache_id); 
    83102    @unlink($file_name); 
    84103} 
     
    86105// Delete the entire disk cache 
    87106function disk_cache_purge() { 
    88     foreach (glob(IA_ROOT_DIR . 'cache/[^.]*') as $file_name) { 
    89         @unlink($file_name); 
     107    foreach (glob(IA_ROOT_DIR . "cache/*", GLOB_ONLYDIR) as $dir_name) { 
     108        _recursive_delete($dir_name); 
     109    } 
     110 
     111    foreach (glob(IA_ROOT_DIR . "cache/*") as $file_name) { 
     112        unlink($file_name); 
    90113    } 
    91114} 
     
    167190 
    168191    // Purge the entire SHM cache. 
    169     // FIXME: does this actually work? 
     192    // FIXME: This does not work 
    170193    function mem_cache_purge() { 
    171194        if (IA_LOG_MEM_CACHE) { 
  • trunk/common/db/job.php

    r963 r965  
    257257    if (!isset($wheres[1])) { 
    258258        // if we have no filters outside of `ia_job` table then optimize query 
    259         $subquery = sprintf(" 
     259        $subquery = " 
    260260            SELECT `job`.`id` AS `ID` 
    261261            FROM `ia_job` as `job` 
    262262            WHERE (" . implode(") AND (", $wheres_job) . ") 
    263             ORDER BY `id` DESC LIMIT %s, %s", 
    264             $start, $range); 
     263            ORDER BY `id` DESC LIMIT {$start}, {$range}"; 
    265264 
    266265        $job_ids_fetched = db_fetch_all($subquery); 
  • trunk/scripts/ia_job_reindex

    r963 r965  
    44 
    55db_connect(); 
    6 $query = "ALTER TABLE `webdb`.`ia_job` 
     6$query = "ALTER TABLE `ia_job` 
    77    DROP INDEX `by_round`, 
    88    ADD INDEX by_round USING BTREE(`round_id`, `id`), 
Note: See TracChangeset for help on using the changeset viewer.