Roxen.git / server / modules / tags / insert_cached_href.pike

version» Context lines:

Roxen.git/server/modules/tags/insert_cached_href.pike:1:   // This is a roxen module. Copyright © 2000 - 2009, Roxen IS.   //      #include <module.h>   inherit "module";      //<locale-token project="mod_insert_cached_href">LOCALE</locale-token>   #define LOCALE(X,Y) _DEF_LOCALE("mod_insert_cached_href",X,Y)    - constant cvs_version = "$Id: insert_cached_href.pike,v 1.34 2012/11/08 13:52:52 jonasw Exp $"; + constant cvs_version = "$Id$";      constant thread_safe = 1;   constant module_type = MODULE_TAG;   LocaleString module_name = LOCALE(1, "Tags: Insert cached href");   LocaleString module_doc = LOCALE(2, "This module contains the RXML tag \"insert "    "cached-href\". Useful when implementing e.g."    " RSS syndication.");      #if DEBUG_INSERT_CACHED_HREF   #define DWRITE(x) report_debug("INSERT_CACHED_HREF: " + x + "\n")
Roxen.git/server/modules/tags/insert_cached_href.pike:304:   /* This class represents the database in which the data of the URL:s are stored */   class HrefDatabase {    private constant request_table_def = "url VARCHAR(255) NOT NULL,"    "fetch_interval INT UNSIGNED NOT NULL,"    "fresh_time INT UNSIGNED NOT NULL,"    "ttl INT UNSIGNED NOT NULL,"    "timeout INT UNSIGNED NOT NULL,"    "time_of_day INT UNSIGNED NOT NULL,"    "next_fetch INT UNSIGNED,"    "latest_request INT UNSIGNED," +  "out_of_date INT UNSIGNED,"    "PRIMARY KEY (url, fetch_interval, "    "fresh_time, ttl, timeout, time_of_day)";       private constant data_table_def = "url VARCHAR(255) NOT NULL,"    "data LONGBLOB,"    "latest_write INT UNSIGNED,"    "PRIMARY KEY (url)";       private string request_table;    private string data_table;       public void create() { -  // Failure to create tables will lead to zero return values +  // Failure to create tables will lead to zero return values.    request_table = get_my_table("request", ({request_table_def}));    data_table = get_my_table("data", ({data_table_def})); -  +  +  // If request_table exists but not the column out_of_date, create +  // indexed column out_of_date and populate it with the sum of +  // latest_request and ttl to optimize the remove_old_entrys. +  if(request_table && !sizeof(sql_query("DESCRIBE " + request_table + " out_of_date"))) { +  sql_query("ALTER TABLE " + request_table + " ADD COLUMN out_of_date INT UNSIGNED;"); +  sql_query("ALTER TABLE " + request_table + " ADD INDEX " + request_table + "(out_of_date);");    } -  +  }       public void empty_db() {    /*    Might as well clean up the database in a mutex section,    just to be sure. No performance issue since this function is only    supposed to be used when the "Clear database" button in the admin interface    is pressed.    */   #ifdef THREADS    mutex_key = mutex->lock();
Roxen.git/server/modules/tags/insert_cached_href.pike:419:    " SET latest_request = " + now +    " WHERE url = %s "    " AND fetch_interval = %d "    " AND fresh_time = %d "    " AND ttl = %d "    " AND timeout = %d "    " AND time_of_day = %d",    url, args["fetch-interval"], args["fresh-time"], args["ttl"],    args["timeout"], args["time-of-day"]);    +     sql_query("INSERT IGNORE INTO " + request_table + -  " VALUES (%s, %d, %d, %d, %d, %d, %d, %d)", +  " VALUES (%s, %d, %d, %d, %d, %d, %d, %d, %d)",    url,    args["fetch-interval"], args["fresh-time"], args["ttl"], -  args["timeout"], args["time-of-day"], next_fetch, now); +  args["timeout"], args["time-of-day"], next_fetch, now, +  (args["ttl"] + now));       sql_query("INSERT IGNORE INTO " + data_table +    " VALUES (%s, '', 0)",    url);       result = sql_query("SELECT data "    " FROM " + data_table +    " WHERE url = %s "    " AND (" + now + " - latest_write < %d "    " OR %d = 0)",
Roxen.git/server/modules/tags/insert_cached_href.pike:477:    to_fetch += ({(["url":url, "timeout":timeout])});       return to_fetch;    }       private int nr_of_requests() {    return sizeof(sql_query("SELECT url from " + request_table));    }       private void remove_old_entrys() { +  +  sql_query("UPDATE " + request_table + +  " SET out_of_date = (latest_request + ttl)" + +  " WHERE out_of_date IS NULL" + +  " AND latest_request IS NOT NULL;"); +     sql_query("DELETE FROM " + request_table + -  " WHERE " + time() + " - latest_request > ttl"); +  " WHERE " + time() + " > out_of_date");       sql_query(" DELETE " + data_table +    " FROM " + data_table +    " LEFT JOIN " + request_table +    " ON " + data_table + ".url=" + request_table + ".url "    " WHERE " + request_table + ".url IS NULL");    }       private array(mapping(string:mixed)) urls_to_fetch() {    array(mapping(string:mixed)) to_fetch = ({});