pike.git / lib / modules / Search.pmod / Utils.pmod

version» Context lines:

pike.git/lib/modules/Search.pmod/Utils.pmod:1:   // This file is part of Roxen Search   // Copyright © 2001 - 2009, Roxen IS. All rights reserved.   // - // $Id: Utils.pmod,v 1.49 2009/05/25 18:26:52 mast Exp $ + // $Id: Utils.pmod,v 1.50 2010/04/28 12:10:35 noring Exp $      #if !constant(report_error)   #define report_error werror   #define report_debug werror   #define report_warning werror   #endif      #ifdef SEARCH_DEBUG   # define WERR(X) report_debug("search: "+(X)+"\n");   #else
pike.git/lib/modules/Search.pmod/Utils.pmod:664:   }         //!   class Logger {       private string|Sql.Sql logdb;    private int profile;    private int stderr_logging;    +  private int last_log_purge_time; +  private constant log_purge_freq = 8*60*60; // Purge log every 8 h or so. +     private Sql.Sql get_db() {    Sql.Sql db;   #if constant(DBManager)    if(stringp(logdb))    db = DBManager.get(logdb);    else   #endif    db = logdb;       // if(!logdb || !logdb->query)
pike.git/lib/modules/Search.pmod/Utils.pmod:717:    werror(sprintf("%sSearch: %s: %s\n",    " : ",    types[type],    extra?sprintf(codes[(int)code], @(extra/"\n")):codes[(int)code]));    }       void log_purge(int days)    {    Sql.Sql db = get_db();    if(!db) return; +  int t1 = time(); +  if (t1 < last_log_purge_time + log_purge_freq) return; +  last_log_purge_time = t1;    if(days)    db->query("DELETE FROM eventlog "    " WHERE at <= NOW() - INTERVAL "+days+" DAY");    else -  db->query("DELETE FROM eventlog"); +  db->query("DELETE FROM eventlog"); // FIXME: TRUNCATE TABLE? +  db->query("OPTIMIZE TABLE eventlog"); +  int t2 = time(); +  if (t2 - t1 > 10) // More than 10 s is somewhat slow, report warning. +  report_warning("Search log purge took %d s.\n", t2-t1);    }       //!    void log_event( int code, string type, void|string extra, void|int log_profile ) {    Sql.Sql db = get_db();    if(!db) return;       if(zero_type(log_profile))    log_profile = profile;