Branch: Tag:

2013-03-12

2013-03-12 10:41:07 by Jenny Sergent <jenny@roxen.com>

Added an indexed column out_of_date to avoid full table scan.

Fixes [bug 6680]. Added a indexed column out_of_date to the insert
request table containing the sum of ttl and latest_request in order to
perform more efficient removal of out of date entries.

7:   //<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;
311:    "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)";   
323:    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() {    /*
426:    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)",
484:    }       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 +