maintain last active state for users
This commit is contained in:
parent
47fba66712
commit
970a9e24cf
@ -116,8 +116,13 @@ def get_metas_db(flag='r', autocommit=True):
|
||||
|
||||
def get_tags_db(flag='r', autocommit=True):
|
||||
assert flag in ['r', 'c']
|
||||
ddb = CompressedSqliteDict(DICT_DB_FILE, tablename='tags', flag=flag, autocommit=autocommit)
|
||||
return ddb
|
||||
tdb = CompressedSqliteDict(DICT_DB_FILE, tablename='tags', flag=flag, autocommit=autocommit)
|
||||
return tdb
|
||||
|
||||
def get_last_active_db(flag='r', autocommit=True):
|
||||
assert flag in ['r', 'c']
|
||||
ladb = SqliteDict(DICT_DB_FILE, tablename='last_active', flag=flag, autocommit=autocommit)
|
||||
return ladb
|
||||
|
||||
# -----------------------------------------------------------------------------
|
||||
"""
|
||||
|
||||
8
serve.py
8
serve.py
@ -19,7 +19,7 @@ from flask import render_template
|
||||
from flask import g # global session-level object
|
||||
from flask import session
|
||||
|
||||
from aslite.db import get_papers_db, get_metas_db, get_tags_db
|
||||
from aslite.db import get_papers_db, get_metas_db, get_tags_db, get_last_active_db
|
||||
from aslite.db import load_features
|
||||
|
||||
# -----------------------------------------------------------------------------
|
||||
@ -65,6 +65,12 @@ def get_metas():
|
||||
def before_request():
|
||||
g.user = session.get('user', None)
|
||||
|
||||
# record activity on this user so we can reserve periodic
|
||||
# recommendations heavy compute only for active users
|
||||
if g.user:
|
||||
with get_last_active_db(flag='c') as last_active_db:
|
||||
last_active_db[g.user] = int(time.time())
|
||||
|
||||
@app.teardown_request
|
||||
def close_connection(error=None):
|
||||
# close any opened database connections
|
||||
|
||||
Loading…
Reference in New Issue
Block a user