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

version» Context lines:

Roxen.git/server/modules/tags/insert_cached_href.pike:296:    href_database->update_data(to_fetch["url"], data);    return data;    } else    return "";   #endif   }         /* 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," +  private constant request_table_def = "url VARCHAR(768) 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," +  private constant data_table_def = "url VARCHAR(768) 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.    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);");    } -  +  +  // Upgrade url field to hold longer strings. We must still respect a +  // limit of the PRIMARY KEY on 1000 bytes, so 768 is a good amount. +  if (request_table) { +  array(mapping) tbl_def = sql_query("DESCRIBE " + request_table + " url"); +  if (sizeof(tbl_def) && lower_case(tbl_def[0]->Type) != "varchar(768)") +  sql_query("ALTER TABLE " + request_table + +  " MODIFY url VARCHAR(768) NOT NULL");    } -  +  if (data_table) { +  array(mapping) tbl_def = sql_query("DESCRIBE " + data_table + " url"); +  if (sizeof(tbl_def) && lower_case(tbl_def[0]->Type) != "varchar(768)") +  sql_query("ALTER TABLE " + data_table + +  " MODIFY url VARCHAR(768) NOT NULL"); +  } +  }       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();