Skip to content

Commit

Permalink
optimize Activity SQL query (#279)
Browse files Browse the repository at this point in the history
  • Loading branch information
likesclever authored Mar 15, 2023
1 parent 403ab16 commit 766838b
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 deletions events/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,12 +120,11 @@ def save_user_activities(session, records):
if len(records) == 1 and records[0]['op_type'] == 'edit':
record = records[0]
_timestamp = record['timestamp'] - timedelta(minutes=30)
q = session.query(Activity)
q = session.query(Activity).filter(Activity.timestamp > _timestamp)
q = q.filter(Activity.repo_id==record['repo_id'],
Activity.op_type==record['op_type'],
Activity.op_user==record['op_user'],
Activity.path==record['path'],
Activity.timestamp > _timestamp)
Activity.path==record['path'])
row = q.first()
if row:
activity_id = row.id
Expand Down

0 comments on commit 766838b

Please sign in to comment.