fix: show proper total balances fix cleanups (#2490)
payments are not deleted oif we delete a wallets, so to get a accurate total representation of the lnbits balance we need to create the balances view based on the wallets table, not payments, else deleted balances will still show up. 2nd, delete_unused_wallets and delete_accounts was never working if because they never got an updated_at time, so i just check if its null else i check to timedelta on created_at
This commit is contained in:
+18
-4
@@ -207,14 +207,21 @@ async def delete_accounts_no_wallets(
|
||||
time_delta: int,
|
||||
conn: Optional[Connection] = None,
|
||||
) -> None:
|
||||
delta = int(time()) - time_delta
|
||||
await (conn or db).execute(
|
||||
f"""
|
||||
DELETE FROM accounts
|
||||
WHERE NOT EXISTS (
|
||||
SELECT wallets.id FROM wallets WHERE wallets.user = accounts.id
|
||||
) AND updated_at < {db.timestamp_placeholder}
|
||||
) AND (
|
||||
(updated_at is null AND created_at < {db.timestamp_placeholder})
|
||||
OR updated_at < {db.timestamp_placeholder}
|
||||
)
|
||||
""",
|
||||
(int(time()) - time_delta,),
|
||||
(
|
||||
delta,
|
||||
delta,
|
||||
),
|
||||
)
|
||||
|
||||
|
||||
@@ -588,14 +595,21 @@ async def delete_unused_wallets(
|
||||
time_delta: int,
|
||||
conn: Optional[Connection] = None,
|
||||
) -> None:
|
||||
delta = int(time()) - time_delta
|
||||
await (conn or db).execute(
|
||||
f"""
|
||||
DELETE FROM wallets
|
||||
WHERE (
|
||||
SELECT COUNT(*) FROM apipayments WHERE wallet = wallets.id
|
||||
) = 0 AND updated_at < {db.timestamp_placeholder}
|
||||
) = 0 AND (
|
||||
(updated_at is null AND created_at < {db.timestamp_placeholder})
|
||||
OR updated_at < {db.timestamp_placeholder}
|
||||
)
|
||||
""",
|
||||
(int(time()) - time_delta,),
|
||||
(
|
||||
delta,
|
||||
delta,
|
||||
),
|
||||
)
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user