File tree Expand file tree Collapse file tree 1 file changed +6
-17
lines changed Expand file tree Collapse file tree 1 file changed +6
-17
lines changed Original file line number Diff line number Diff line change @@ -468,24 +468,13 @@ def cleanup_sessions():
468
468
469
469
try :
470
470
logging .info ("Deleting sessions..." )
471
- before = len (
472
- session .execute (
473
- text ("SELECT * FROM session WHERE expiry < now()::timestamp(0);" )
474
- )
475
- .mappings ()
476
- .all ()
477
- )
471
+ count_statement = "SELECT COUNT(*) AS cnt FROM session WHERE expiry < now()::timestamp(0);"
472
+ before = session .execute (text (count_statement )).one_or_none ()["cnt" ]
478
473
session .execute (text ("DELETE FROM session WHERE expiry < now()::timestamp(0);" ))
479
- after = len (
480
- session .execute (
481
- text ("SELECT * FROM session WHERE expiry < now()::timestamp(0);" )
482
- )
483
- .mappings ()
484
- .all ()
485
- )
486
- logging .info ("Deleted {} expired sessions." .format (before - after ))
487
- except Exception as e :
488
- logging .error (e )
474
+ after = session .execute (text (count_statement )).one_or_none ()["cnt" ]
475
+ logging .info ("Deleted %s expired sessions." , (before - after ))
476
+ except Exception as err :
477
+ logging .exception (err )
489
478
490
479
session .commit ()
491
480
session .close ()
You can’t perform that action at this time.
0 commit comments