From 20d7bbb212cf29401db89cfb89a2f8cde5c93693 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=A1lli=20Zolt=C3=A1n?= Date: Mon, 15 Nov 2021 23:02:33 +0100 Subject: [PATCH] rebalancereport calls listpays once I had several successful rebalances, and when I call `rebalancereport` it takes some time to collect info about them. A possible performance improvement: `rebalancereport` does not call `listpays` for every rebalance one by one, but only once. In my case, this changes the execution time from ~140 secs to ~7 secs. --- rebalance/rebalance.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/rebalance/rebalance.py b/rebalance/rebalance.py index 356b951..918c6a7 100755 --- a/rebalance/rebalance.py +++ b/rebalance/rebalance.py @@ -742,9 +742,13 @@ def rebalancereport(plugin: Plugin): total_fee = Millisatoshi(0) total_amount = Millisatoshi(0) res["total_successful_rebalances"] = len(rebalances) + # pyln-client does not support the 'status' argument as yet + # pays = plugin.rpc.listpays(status="complete")["pays"] + pays = plugin.rpc.listpays()["pays"] + pays = [p for p in pays if p.get('status') == 'complete'] for r in rebalances: try: - pay = plugin.rpc.listpays(r["bolt11"])["pays"][0] + pay = next(p for p in pays if p["payment_hash"] == r["payment_hash"]) total_amount += pay["amount_msat"] total_fee += pay["amount_sent_msat"] - pay["amount_msat"] except Exception: