diff --git a/class/core/db.py b/class/core/db.py index 91256ae7a..5a92a33f9 100755 --- a/class/core/db.py +++ b/class/core/db.py @@ -151,7 +151,9 @@ class Sql(): try: sql = "SELECT " + self.__OPT_FIELD + " FROM " + self.__DB_TABLE + \ self.__OPT_WHERE + self.__OPT_GROUP + self.__OPT_ORDER + self.__OPT_LIMIT - # print(sql, self.__OPT_PARAM) + + if os.path.exists('data/debug.pl'): + print(sql, self.__OPT_PARAM) result = self.__DB_CONN.execute(sql, self.__OPT_PARAM) data = result.fetchall() # 构造字曲系列 diff --git a/plugins/webstats/conf/init.sql b/plugins/webstats/conf/init.sql index 2764ea74c..c7b548262 100644 --- a/plugins/webstats/conf/init.sql +++ b/plugins/webstats/conf/init.sql @@ -23,7 +23,15 @@ CREATE TABLE IF NOT EXISTS `web_logs` ( `client_port` INTEGER DEFAULT -1 ); -CREATE INDEX time_inx ON web_logs(`time`); +CREATE INDEX time_idx ON web_logs(`time`); +CREATE INDEX uri_idx ON web_logs (`uri`); +CREATE INDEX ip_idx ON web_logs (`ip`); +CREATE INDEX referer_idx ON web_logs (`referer`); +CREATE INDEX method_idx ON web_logs (`method`); +CREATE INDEX status_code_idx ON web_logs (`status_code`); +CREATE INDEX request_time_idx ON web_logs (`request_time`); +CREATE INDEX is_spider_idx ON web_logs (`is_spider`); +CREATE INDEX all_union_idx ON web_logs (`time`,`ip`,`method`,`status_code`,`request_time`,`is_spider`); CREATE TABLE IF NOT EXISTS `client_stat`( diff --git a/plugins/webstats/webstats_index.py b/plugins/webstats/webstats_index.py index 44aa4d02a..2d462897a 100644 --- a/plugins/webstats/webstats_index.py +++ b/plugins/webstats/webstats_index.py @@ -731,11 +731,19 @@ def get_logs_list(args): conn = conn.field(field) conn = conn.where("1=1", ()) - if referer != 'all': - if referer == '1': - conn = conn.andWhere("referer <> ? ", ('',)) - elif referer == '-1': - conn = conn.andWhere("referer is null ", ()) + todayTime = time.strftime('%Y-%m-%d 00:00:00', time.localtime()) + todayUt = int(time.mktime(time.strptime(todayTime, "%Y-%m-%d %H:%M:%S"))) + if query_date == 'today': + conn = conn.andWhere("time>=?", (todayUt,)) + elif query_date == "yesterday": + conn = conn.andWhere("time>=? and time<=?", (todayUt - 86400, todayUt)) + elif query_date == "l7": + conn = conn.andWhere("time>=?", (todayUt - 7 * 86400,)) + elif query_date == "l30": + conn = conn.andWhere("time>=?", (todayUt - 30 * 86400,)) + else: + exlist = query_date.split("-") + conn = conn.andWhere("time>=? and time<=?", (exlist[0], exlist[1])) if ip != '': conn = conn.andWhere("ip=?", (ip,)) @@ -763,19 +771,11 @@ def get_logs_list(args): elif int(spider_type) > 0: conn = conn.andWhere("is_spider=?", (spider_type,)) - todayTime = time.strftime('%Y-%m-%d 00:00:00', time.localtime()) - todayUt = int(time.mktime(time.strptime(todayTime, "%Y-%m-%d %H:%M:%S"))) - if query_date == 'today': - conn = conn.andWhere("time>=?", (todayUt,)) - elif query_date == "yesterday": - conn = conn.andWhere("time>=? and time<=?", (todayUt - 86400, todayUt)) - elif query_date == "l7": - conn = conn.andWhere("time>=?", (todayUt - 7 * 86400,)) - elif query_date == "l30": - conn = conn.andWhere("time>=?", (todayUt - 30 * 86400,)) - else: - exlist = query_date.split("-") - conn = conn.andWhere("time>=? and time<=?", (exlist[0], exlist[1])) + if referer != 'all': + if referer == '1': + conn = conn.andWhere("referer <> ? ", ('',)) + elif referer == '-1': + conn = conn.andWhere("referer is null ", ()) if search_uri != "": conn = conn.andWhere("uri like '%" + search_uri + "%'", ())