Ejemplo n.º 1
0
/**
 * Hook into the task scheduler. This uses the queries defined in the cache_builder.php
 * file to create and populate cache tables. The tables are not always up to date as they
 * are only updated when the scheduler runs, but they have the advantage of simplifying
 * the data model for reporting as well as reducing the need to join in queries, therefore
 * significantly improving report performance.
 * @param string $last_run_date Date last run, or null if never run
 * @param object $db Database object.
 */
function cache_builder_scheduled_task($last_run_date, $db)
{
    if (isset($_GET['force_cache_rebuild'])) {
        $last_run_date = date('Y-m-d', time() - 60 * 60 * 24 * 365 * 200);
    } elseif ($last_run_date === null) {
        // first run, so get all records changed in last day. Query will automatically gradually pick up the rest.
        $last_run_date = date('Y-m-d', time() - 60 * 60 * 24);
    }
    try {
        foreach (kohana::config('cache_builder') as $table => $queries) {
            cache_builder::populate_cache_table($db, $table, $last_run_date);
            if (!variable::get("populated-{$table}")) {
                // don't bother populating the next table, as there can be dependencies.
                break;
            }
        }
    } catch (Exception $e) {
        echo $e->getMessage();
    }
}