mirror of
https://github.com/lnbits/lnbits.git
synced 2025-09-27 20:36:16 +02:00
improve invoice deleting code.
This commit is contained in:
@@ -267,11 +267,22 @@ async def get_payments(
|
|||||||
async def delete_expired_invoices(
|
async def delete_expired_invoices(
|
||||||
conn: Optional[Connection] = None,
|
conn: Optional[Connection] = None,
|
||||||
) -> None:
|
) -> None:
|
||||||
|
# first we delete all invoices older than one month
|
||||||
|
await (conn or db).execute(
|
||||||
|
"""
|
||||||
|
DELETE FROM apipayments
|
||||||
|
WHERE pending = 1 AND amount > 0 AND time < strftime('%s', 'now') - 2592000
|
||||||
|
"""
|
||||||
|
)
|
||||||
|
|
||||||
|
# then we delete all expired invoices, checking one by one
|
||||||
rows = await (conn or db).fetchall(
|
rows = await (conn or db).fetchall(
|
||||||
"""
|
"""
|
||||||
SELECT bolt11
|
SELECT bolt11
|
||||||
FROM apipayments
|
FROM apipayments
|
||||||
WHERE pending = 1 AND amount > 0 AND time < strftime('%s', 'now') - 86400
|
WHERE pending = 1
|
||||||
|
AND bolt11 IS NOT NULL
|
||||||
|
AND amount > 0 AND time < strftime('%s', 'now') - 86400
|
||||||
"""
|
"""
|
||||||
)
|
)
|
||||||
for (payment_request,) in rows:
|
for (payment_request,) in rows:
|
||||||
|
Reference in New Issue
Block a user