mirror of
https://github.com/lnbits/lnbits.git
synced 2025-09-26 03:46:17 +02:00
optimize balances view (#1779)
* optimize balances view flake8 flake8 * fix line length
This commit is contained in:
@@ -302,3 +302,20 @@ async def m010_create_installed_extensions_table(db):
|
||||
);
|
||||
"""
|
||||
)
|
||||
|
||||
|
||||
async def m011_optimize_balances_view(db):
|
||||
"""
|
||||
Make the calculation of the balance a single aggregation
|
||||
over the payments table instead of 2.
|
||||
"""
|
||||
await db.execute("DROP VIEW balances")
|
||||
await db.execute(
|
||||
"""
|
||||
CREATE VIEW balances AS
|
||||
SELECT wallet, SUM(amount - abs(fee)) AS balance
|
||||
FROM apipayments
|
||||
WHERE (pending = false AND amount > 0) OR amount < 0
|
||||
GROUP BY wallet
|
||||
"""
|
||||
)
|
||||
|
Reference in New Issue
Block a user