speed up redis-based dup detection by avoiding touching the DB in before_request() #135

This commit is contained in:
rimu 2024-04-09 08:14:25 +12:00
parent 6485f201d3
commit 5c3fb82ebb
2 changed files with 3 additions and 1 deletions

View file

@ -374,6 +374,7 @@ def shared_inbox():
redis_client.set(request_json['id'], 1, ex=90) # Save the activity ID into redis, to avoid duplicate activities that Lemmy sometimes sends
activity_log.activity_id = request_json['id']
g.site = Site.query.get(1) # g.site is not initialized by @app.before_request when request.path == '/inbox'
if g.site.log_activitypub_json:
activity_log.activity_json = json.dumps(request_json)
activity_log.result = 'processing'

View file

@ -53,7 +53,8 @@ with app.app_context():
def before_request():
session['nonce'] = gibberish()
g.locale = str(get_locale())
g.site = Site.query.get(1)
if request.path != '/inbox' and not request.path.startswith('/static/'): # do not load g.site on shared inbox, to increase chance of duplicate detection working properly
g.site = Site.query.get(1)
if current_user.is_authenticated:
current_user.last_seen = datetime.utcnow()
current_user.email_unread_sent = False