weekly.monday.4am.php 1.64 KB
Newer Older
Ayolo's avatar
Ayolo committed
1
<?php
2 3
if(!isset($argc))
  exit();
Antoine Tenart's avatar
kwain  
Antoine Tenart committed
4
$_SERVER['SCRIPT_FILENAME']="/var/www/ae2/phpcron";
Ayolo's avatar
Ayolo committed
5

Ayolo's avatar
fix  
Ayolo committed
6
$topdir=$_SERVER['SCRIPT_FILENAME']."/../";
Ayolo's avatar
Ayolo committed
7 8 9 10 11 12
require_once($topdir. "include/site.inc.php");

$site = new site ();

echo "==== ".date("d/m/Y")." ====\n";

Ayolo's avatar
Ayolo committed
13 14
echo ">> OPTIMZE TABLES\n";
$req = new requete($site->db, 'SHOW TABLES');
BenC's avatar
Fix  
BenC committed
15
while(list($table)=$req->get_row())
Ayolo's avatar
Ayolo committed
16 17
  new requete($site->dbrw, 'OPTIMIZE TABLE \''.$table.'\'');

18 19 20 21
// On regenere entierement le cache fsearch pour prendre en compte les nouvelles popularites
echo ">> BEGIN FSEARCH CACHE REGEN: ".date('r')."\n";
require_once ($topdir. "include/cts/fsearch.inc.php");
require_once ($topdir. "include/redis.inc.php");
Ayolo's avatar
Ayolo committed
22

23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57
$redis = redis_open_connection ();
// We remove all entries from this database
$redis->flushDB();
$redis->set ('_disable_cache', true);
$letters = array ('a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z');

function compute_pattern_with_size ($size)
{
    global $site, $redis;

    // we do all combination of 4 character
    $upper = pow (26, $size);

    for ($i = 0; $i < $upper; ++$i) {
        $str = '';
        for ($j = $size - 1; $j >= 0; $j--)
            $str .= $letters[($i / pow (26, $j)) % 26];

        $_REQUEST['pattern'] = $str;

        $fsearch = new fsearch ($site, false, true);
        if (!empty ($fsearch->buffer))
            $redis->set($str, $fsearch->buffer);
    }
}

compute_pattern_with_size (1);
compute_pattern_with_size (2);
compute_pattern_with_size (3);
compute_pattern_with_size (4);

$redis->del ('_disable_cache');
$redis->close ();

echo ">> END FSEARCH CACHE REGEN: ".date('r')."\n";
Ayolo's avatar
Ayolo committed
58

Ayolo's avatar
hack  
Ayolo committed
59
?>