Skip to content

Commit 37720e3

Browse files
committed
improve sql of get_cells_capacity.
1 parent cdd40b0 commit 37720e3

File tree

1 file changed

+4
-15
lines changed

1 file changed

+4
-15
lines changed

util/rich-indexer/src/indexer_handle/async_indexer_handle.rs

+4-15
Original file line numberDiff line numberDiff line change
@@ -332,15 +332,7 @@ impl AsyncRichIndexerHandle {
332332

333333
// query output
334334
let mut query_builder = SqlBuilder::select_from("output");
335-
query_builder.field("output.capacity");
336-
match search_key.with_data {
337-
Some(true) | None => {
338-
query_builder.field("output.data as output_data");
339-
}
340-
Some(false) => {
341-
query_builder.field("NULL as output_data");
342-
}
343-
}
335+
query_builder.field("SUM(output.capacity) as total_capacity");
344336
query_builder.join(&format!("{} script_res", script_sub_query_sql));
345337
match search_key.script_type {
346338
IndexerScriptType::Lock => {
@@ -426,13 +418,10 @@ impl AsyncRichIndexerHandle {
426418

427419
// fetch
428420
let capacity = query
429-
.fetch_all(&mut *tx)
421+
.fetch_one(&mut *tx)
430422
.await
431-
.map_err(|err| Error::DB(err.to_string()))?
432-
.iter()
433-
.map(|row| row.get::<i64, _>("capacity") as u64)
434-
.sum::<u64>();
435-
423+
.map(|row| row.get::<i64, _>("total_capacity") as u64)
424+
.map_err(|err| Error::DB(err.to_string()))?;
436425
if capacity == 0 {
437426
return Ok(None);
438427
}

0 commit comments

Comments
 (0)