expire_locks.sql (1582B)
1 -- 2 -- This file is part of TALER 3 -- Copyright (C) 2026 Taler Systems SA 4 -- 5 -- TALER is free software; you can redistribute it and/or modify it under the 6 -- terms of the GNU General Public License as published by the Free Software 7 -- Foundation; either version 3, or (at your option) any later version. 8 -- 9 -- TALER is distributed in the hope that it will be useful, but WITHOUT ANY 10 -- WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR 11 -- A PARTICULAR PURPOSE. See the GNU General Public License for more details. 12 -- 13 -- You should have received a copy of the GNU General Public License along with 14 -- TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/> 15 -- 16 17 18 DROP FUNCTION IF EXISTS expire_locks; 19 CREATE FUNCTION expire_locks( 20 IN in_now INT8 21 ) 22 RETURNS INT8 23 LANGUAGE plpgsql 24 AS $$ 25 DECLARE 26 rec RECORD; 27 s TEXT; 28 total INT8 := 0; 29 affected INT8; 30 BEGIN 31 DELETE FROM merchant_inventory_locks 32 WHERE expiration < in_now; 33 GET DIAGNOSTICS affected = ROW_COUNT; 34 total := total + affected; 35 36 DELETE FROM merchant_orders 37 WHERE pay_deadline < in_now; 38 GET DIAGNOSTICS affected = ROW_COUNT; 39 total := total + affected; 40 41 DELETE FROM merchant_contract_terms 42 WHERE NOT paid 43 AND pay_deadline < in_now; 44 GET DIAGNOSTICS affected = ROW_COUNT; 45 total := total + affected; 46 RETURN total; 47 END 48 $$; 49 50 COMMENT ON FUNCTION expire_locks(INT8) 51 IS 'DELETEs expired inventory locks, unpaid orders past their' 52 ' pay_deadline, and unpaid contracts past their' 53 ' pay_deadline. Returns the total number of rows deleted.';