fix: update last_login every 5min so profile shows current activity
Some checks are pending
NordaBiz Tests / Unit & Integration Tests (push) Waiting to run
NordaBiz Tests / E2E Tests (Playwright) (push) Blocked by required conditions
NordaBiz Tests / Smoke Tests (Production) (push) Blocked by required conditions
NordaBiz Tests / Send Failure Notification (push) Blocked by required conditions
Some checks are pending
NordaBiz Tests / Unit & Integration Tests (push) Waiting to run
NordaBiz Tests / E2E Tests (Playwright) (push) Blocked by required conditions
NordaBiz Tests / Smoke Tests (Production) (push) Blocked by required conditions
NordaBiz Tests / Send Failure Notification (push) Blocked by required conditions
before_request middleware refreshes last_login in session-throttled manner (max once per 5 minutes) to avoid showing stale activity. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
eaf29b0aa2
commit
2f6aefdea9
25
app.py
25
app.py
@ -615,6 +615,31 @@ def check_geoip():
|
||||
abort(403)
|
||||
|
||||
|
||||
@app.before_request
|
||||
def update_last_active():
|
||||
"""Update last_login periodically (every 5 min) so profile shows fresh activity."""
|
||||
if not current_user.is_authenticated:
|
||||
return
|
||||
if request.path.startswith('/static') or request.path == '/health':
|
||||
return
|
||||
from flask import session as flask_session
|
||||
import time
|
||||
now = time.time()
|
||||
last_update = flask_session.get('_last_active_update', 0)
|
||||
if now - last_update < 300: # 5 minutes
|
||||
return
|
||||
flask_session['_last_active_update'] = now
|
||||
try:
|
||||
db = SessionLocal()
|
||||
user = db.query(User).filter_by(id=current_user.id).first()
|
||||
if user:
|
||||
user.last_login = datetime.now()
|
||||
db.commit()
|
||||
db.close()
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
|
||||
@app.before_request
|
||||
def track_page_view():
|
||||
"""Track page views (excluding static files and API calls)"""
|
||||
|
||||
Loading…
Reference in New Issue
Block a user