@@ -43,16 +43,18 @@ func (db *TokenLockStore) Cleanup(ctx context.Context, leaseExpiry time.Duration
4343 if err := db .logStaleLocks (ctx , leaseExpiry ); err != nil {
4444 db .Logger .Warnf ("Could not log stale locks: %v" , err )
4545 }
46- tokenLocks , tokenRequests := q .Table (db .Table .TokenLocks ), q .Table (db .Table .Requests )
46+ tokenLocks , _ := q .Table (db .Table .TokenLocks ), q .Table (db .Table .Requests )
47+
4748 query , args := common3 .NewBuilder ().
4849 WriteString ("DELETE FROM " ).
4950 WriteConditionSerializable (tokenLocks , db .ci ).
50- WriteString (" USING " ).
51- WriteConditionSerializable (tokenRequests , db .ci ).
5251 WriteString (" WHERE " ).
53- WriteConditionSerializable (cond .And (
54- cond .Cmp (tokenLocks .Field ("consumer_tx_id" ), "=" , tokenRequests .Field ("tx_id" )),
55- common .IsExpiredToken (tokenRequests , tokenLocks , leaseExpiry )), db .ci ).
52+ WriteConditionSerializable (cond .OlderThan (tokenLocks .Field ("created_at" ), leaseExpiry ), db .ci ).
53+ WriteString (" OR " ).
54+ WriteString (
55+ fmt .Sprintf ("EXISTS (SELECT 1 FROM %s WHERE %s.tx_id = %s.consumer_tx_id AND %s.status IN (%d))" ,
56+ db .Table .Requests , db .Table .Requests , db .Table .TokenLocks , db .Table .Requests , driver .Deleted ,
57+ )). //TODO: Implement EXIST condition
5658 Build ()
5759
5860 db .Logger .Debug (query )
0 commit comments