Skip to content

Commit 0e3ee40

Browse files
committed
don't keep paging if window size is big and we hit the first index
1 parent f42f5ae commit 0e3ee40

3 files changed

Lines changed: 52 additions & 6 deletions

File tree

src/forwards.rs

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,22 @@ async fn process_forward_batches(
128128
.await?
129129
.updated
130130
.unwrap();
131-
log::debug!("Current forward index: {current_index}");
131+
132+
let first_index = rpc
133+
.call_typed(&ListforwardsRequest {
134+
status: Some(ListforwardsStatus::SETTLED),
135+
in_channel: None,
136+
out_channel: None,
137+
index: Some(ListforwardsIndex::UPDATED),
138+
start: Some(0),
139+
limit: Some(1),
140+
})
141+
.await?
142+
.forwards
143+
.first()
144+
.and_then(|f| f.updated_index)
145+
.unwrap_or(0);
146+
log::debug!("Current forward index: {current_index}, first index: {first_index}");
132147

133148
let mut loop_count = 0;
134149

@@ -161,7 +176,7 @@ async fn process_forward_batches(
161176
)
162177
.await?;
163178

164-
if current_index <= 1 {
179+
if current_index <= 1 || current_index <= first_index {
165180
break;
166181
}
167182
limit = u32::min(u32::try_from(PAGE_SIZE)?, u32::try_from(current_index)?);

src/invoices.rs

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,23 @@ async fn process_invoice_batches(
9999
.await?
100100
.updated
101101
.unwrap();
102-
log::debug!("Current invoices index: {current_index}");
102+
103+
let first_index = rpc
104+
.call_typed(&ListinvoicesRequest {
105+
label: None,
106+
invstring: None,
107+
payment_hash: None,
108+
offer_id: None,
109+
index: Some(ListinvoicesIndex::UPDATED),
110+
start: Some(0),
111+
limit: Some(1),
112+
})
113+
.await?
114+
.invoices
115+
.first()
116+
.and_then(|i| i.updated_index)
117+
.unwrap_or(0);
118+
log::debug!("Current invoices index: {current_index}, first index: {first_index}");
103119

104120
let mut loop_count = 0;
105121

@@ -124,7 +140,7 @@ async fn process_invoice_batches(
124140

125141
build_invoices_table(invoices_acc, invoices, full_node_data, config)?;
126142

127-
if current_index <= 1 {
143+
if current_index <= 1 || current_index <= first_index {
128144
break;
129145
}
130146
limit = u32::min(u32::try_from(PAGE_SIZE)?, u32::try_from(current_index)?);

src/pays.rs

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,22 @@ async fn process_pay_batches(
127127
.await?
128128
.updated
129129
.unwrap();
130-
log::debug!("Current pays index: {current_index}");
130+
131+
let first_index = rpc
132+
.call_typed(&ListpaysRequest {
133+
bolt11: None,
134+
payment_hash: None,
135+
status: Some(ListpaysStatus::COMPLETE),
136+
index: Some(ListpaysIndex::UPDATED),
137+
start: Some(0),
138+
limit: Some(1),
139+
})
140+
.await?
141+
.pays
142+
.first()
143+
.and_then(|p| p.updated_index)
144+
.unwrap_or(0);
145+
log::debug!("Current pays index: {current_index}, first index: {first_index}");
131146

132147
let mut loop_count = 0;
133148

@@ -151,7 +166,7 @@ async fn process_pay_batches(
151166

152167
build_pays_table(pays_acc, config, pays, full_node_data, rpc, plugin.clone()).await?;
153168

154-
if current_index <= 1 {
169+
if current_index <= 1 || current_index <= first_index {
155170
break;
156171
}
157172
limit = u32::min(u32::try_from(PAGE_SIZE)?, u32::try_from(current_index)?);

0 commit comments

Comments
 (0)