feat: only check the current page (#3015)

This commit is contained in:
Vlad Stan
2025-03-03 16:28:55 +02:00
committed by GitHub
parent 991e0db50b
commit ec77a00f49
2 changed files with 22 additions and 9 deletions

View File

@@ -178,13 +178,20 @@ async def update_pending_payments(wallet_id: str):
exclude_uncheckable=True,
)
for payment in pending_payments:
status = await payment.check_status()
if status.failed:
payment.status = PaymentState.FAILED
await update_payment(payment)
elif status.success:
payment.status = PaymentState.SUCCESS
await update_payment(payment)
await update_pending_payment(payment)
async def update_pending_payment(payment: Payment) -> bool:
status = await payment.check_status()
if status.failed:
payment.status = PaymentState.FAILED
await update_payment(payment)
return True
if status.success:
payment.status = PaymentState.SUCCESS
await update_payment(payment)
return True
return False
def fee_reserve_total(amount_msat: int, internal: bool = False) -> int:

View File

@@ -37,7 +37,10 @@ from lnbits.core.models import (
Wallet,
)
from lnbits.core.models.users import User
from lnbits.core.services.payments import get_payments_daily_stats
from lnbits.core.services.payments import (
get_payments_daily_stats,
update_pending_payment,
)
from lnbits.db import Filters, Page
from lnbits.decorators import (
WalletTypeInfo,
@@ -180,11 +183,14 @@ async def api_payments_paginated(
key_info: WalletTypeInfo = Depends(require_invoice_key),
filters: Filters = Depends(parse_filters(PaymentFilters)),
):
await update_pending_payments(key_info.wallet.id)
page = await get_payments_paginated(
wallet_id=key_info.wallet.id,
filters=filters,
)
for payment in page.data:
if payment.pending:
await update_pending_payment(payment)
return page