Thread safe access and request log updating in optionalmanager
This commit is contained in:
parent
0af90aad37
commit
39442977db
1 changed files with 18 additions and 8 deletions
|
@ -17,36 +17,46 @@ def importPluginnedClasses():
|
||||||
|
|
||||||
|
|
||||||
def processAccessLog():
|
def processAccessLog():
|
||||||
|
global access_log
|
||||||
if access_log:
|
if access_log:
|
||||||
content_db = ContentDbPlugin.content_db
|
content_db = ContentDbPlugin.content_db
|
||||||
if not content_db.conn:
|
if not content_db.conn:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
s = time.time()
|
||||||
|
access_log_prev = access_log
|
||||||
|
access_log = collections.defaultdict(dict)
|
||||||
now = int(time.time())
|
now = int(time.time())
|
||||||
num = 0
|
num = 0
|
||||||
for site_id in access_log:
|
for site_id in access_log_prev:
|
||||||
content_db.execute(
|
content_db.execute(
|
||||||
"UPDATE file_optional SET time_accessed = %s WHERE ?" % now,
|
"UPDATE file_optional SET time_accessed = %s WHERE ?" % now,
|
||||||
{"site_id": site_id, "inner_path": list(access_log[site_id].keys())}
|
{"site_id": site_id, "inner_path": list(access_log_prev[site_id].keys())}
|
||||||
)
|
)
|
||||||
num += len(access_log[site_id])
|
num += len(access_log_prev[site_id])
|
||||||
access_log.clear()
|
|
||||||
|
content_db.log.debug("Inserted %s web request stat in %.3fs" % (num, time.time() - s))
|
||||||
|
|
||||||
|
|
||||||
def processRequestLog():
|
def processRequestLog():
|
||||||
|
global request_log
|
||||||
if request_log:
|
if request_log:
|
||||||
content_db = ContentDbPlugin.content_db
|
content_db = ContentDbPlugin.content_db
|
||||||
if not content_db.conn:
|
if not content_db.conn:
|
||||||
return False
|
return False
|
||||||
cur = content_db.getCursor()
|
|
||||||
|
s = time.time()
|
||||||
|
request_log_prev = request_log
|
||||||
|
request_log = collections.defaultdict(lambda: collections.defaultdict(int)) # {site_id: {inner_path1: 1, inner_path2: 1...}}
|
||||||
num = 0
|
num = 0
|
||||||
for site_id in request_log:
|
for site_id in request_log_prev:
|
||||||
for inner_path, uploaded in request_log[site_id].items():
|
for inner_path, uploaded in request_log_prev[site_id].items():
|
||||||
content_db.execute(
|
content_db.execute(
|
||||||
"UPDATE file_optional SET uploaded = uploaded + %s WHERE ?" % uploaded,
|
"UPDATE file_optional SET uploaded = uploaded + %s WHERE ?" % uploaded,
|
||||||
{"site_id": site_id, "inner_path": inner_path}
|
{"site_id": site_id, "inner_path": inner_path}
|
||||||
)
|
)
|
||||||
num += 1
|
num += 1
|
||||||
request_log.clear()
|
content_db.log.debug("Inserted %s file request stat in %.3fs" % (num, time.time() - s))
|
||||||
|
|
||||||
|
|
||||||
if "access_log" not in locals().keys(): # To keep between module reloads
|
if "access_log" not in locals().keys(): # To keep between module reloads
|
||||||
|
|
Loading…
Reference in a new issue