Skip to content

Commit

Permalink
Merge pull request #390 from midoks/dev
Browse files Browse the repository at this point in the history
网站统计优化
  • Loading branch information
midoks authored Mar 5, 2023
2 parents d38e9f7 + e129051 commit 704b256
Showing 1 changed file with 25 additions and 6 deletions.
31 changes: 25 additions & 6 deletions plugins/webstats/lua/webstats_common.lua
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,7 @@ function _M.cronPre(self)
local time_key = self:get_store_key()
local time_key_next = self:get_store_key_with_time(ngx.time()+3600)


for site_k, site_v in ipairs(sites) do
local input_sn = site_v["name"]

Expand All @@ -250,16 +251,24 @@ function _M.cronPre(self)
'spider_stat'
}

local v1 = true
local v2 = true
for _,ws_v in pairs(wc_stat) do
self:_update_stat_pre(db, ws_v, time_key)
self:_update_stat_pre(db, ws_v, time_key_next)
v1 = self:_update_stat_pre(db, ws_v, time_key)
v2 = self:_update_stat_pre(db, ws_v, time_key_next)
end

if db and db:isopen() then
db:execute([[COMMIT]])
db:close()
end

if not v1 or not v2 then
return false
end
end

return true
end

-- 后台任务
Expand All @@ -273,7 +282,12 @@ function _M.cron(self)
return true
end

self:cronPre()
-- self:D("dedebide:cron task is busy!")
local ready_ok = self:cronPre()
if not ready_ok then
self:D("cron task is busy!")
return true
end

ngx.update_time()
local begin = ngx.now()
Expand Down Expand Up @@ -653,9 +667,14 @@ end
function _M._update_stat_pre(self, db, stat_table, key)
local local_sql = string.format("INSERT INTO %s(time) SELECT :time WHERE NOT EXISTS(SELECT time FROM %s WHERE time=:time);", stat_table, stat_table)
local update_stat_stmt = db:prepare(local_sql)
update_stat_stmt:bind_names{time=key}
update_stat_stmt:step()
update_stat_stmt:finalize()

if update_stat_stmt then
update_stat_stmt:bind_names{time=key}
update_stat_stmt:step()
update_stat_stmt:finalize()
return true
end
return false
end

function _M.update_stat_quick(self, db, stat_table, key,columns)
Expand Down

0 comments on commit 704b256

Please sign in to comment.