From c693faacde4c33a931c026410dec59e09648346a Mon Sep 17 00:00:00 2001 From: Reckless_Satoshi <90936742+Reckless-Satoshi@users.noreply.github.com> Date: Sun, 30 Apr 2023 13:46:23 +0000 Subject: [PATCH] Optimize follow-invoices service performance (#480) --- api/lightning/node.py | 4 ---- api/management/commands/follow_invoices.py | 6 +++--- 2 files changed, 3 insertions(+), 7 deletions(-) diff --git a/api/lightning/node.py b/api/lightning/node.py index 142d096f..0e36d658 100644 --- a/api/lightning/node.py +++ b/api/lightning/node.py @@ -288,8 +288,6 @@ class LNNode: pass status = lnd_response_state_to_lnpayment_status[response.state] - lnpayment.status = status - lnpayment.save() except Exception as e: # If it fails at finding the invoice: it has been canceled. @@ -297,8 +295,6 @@ class LNNode: if "unable to locate invoice" in str(e): print(str(e)) status = LNPayment.Status.CANCEL - lnpayment.status = status - lnpayment.save() # LND restarted. if "wallet locked, unlock it" in str(e): diff --git a/api/management/commands/follow_invoices.py b/api/management/commands/follow_invoices.py index af02fe26..413a2f73 100644 --- a/api/management/commands/follow_invoices.py +++ b/api/management/commands/follow_invoices.py @@ -59,16 +59,16 @@ class Command(BaseCommand): at_least_one_changed = False for idx, hold_lnpayment in enumerate(queryset): - old_status = LNPayment.Status(hold_lnpayment.status).label + old_status = hold_lnpayment.status - status = LNNode.lookup_invoice_status(hold_lnpayment) - new_status = LNPayment.Status(status).label + new_status = LNNode.lookup_invoice_status(hold_lnpayment) # Only save the hold_payments that change (otherwise this function does not scale) changed = not old_status == new_status if changed: # self.handle_status_change(hold_lnpayment, old_status) self.update_order_status(hold_lnpayment) + hold_lnpayment.status = new_status hold_lnpayment.save() # Report for debugging