query: more optimizations

This commit is contained in:
nym21
2026-04-07 17:43:11 +02:00
parent f022f62cce
commit 17e531b4ee
10 changed files with 162 additions and 109 deletions
+4 -6
View File
@@ -288,7 +288,6 @@ impl Query {
let varint_len = Self::compact_size_len(tx_count);
let coinbase_offset = HEADER_SIZE as u32 + varint_len;
let coinbase_pos = positions[i] + coinbase_offset;
let coinbase_read_len = size as usize - coinbase_offset as usize;
let (
coinbase_raw,
@@ -297,7 +296,7 @@ impl Query {
coinbase_signature,
coinbase_signature_ascii,
scriptsig_bytes,
) = Self::parse_coinbase_tx(reader, coinbase_pos, coinbase_read_len);
) = Self::parse_coinbase_tx(reader, coinbase_pos);
let miner_names = if pool_slug == PoolSlug::Ocean {
Self::parse_datum_miner_names(&scriptsig_bytes)
@@ -514,15 +513,14 @@ impl Query {
fn parse_coinbase_tx(
reader: &Reader,
position: BlkPosition,
len: usize,
) -> (String, Option<String>, Vec<String>, String, String, Vec<u8>) {
let empty = (String::new(), None, vec![], String::new(), String::new(), vec![]);
let raw_bytes = match reader.read_raw_bytes(position, len) {
Ok(bytes) => bytes,
let blk_reader = match reader.reader_at(position) {
Ok(r) => r,
Err(_) => return empty,
};
let tx = match bitcoin::Transaction::consensus_decode(&mut raw_bytes.as_slice()) {
let tx = match bitcoin::Transaction::consensus_decode(&mut bitcoin::io::FromStd::new(blk_reader)) {
Ok(tx) => tx,
Err(_) => return empty,
};
+4 -4
View File
@@ -31,14 +31,14 @@ impl Query {
let start: usize = usize::from(first_height_of_day).min(max_height_usize);
let timestamps = &indexer.vecs.blocks.timestamp;
let mut ts_cursor = indexer.vecs.blocks.timestamp.cursor();
// Search forward from start to find the last block <= target timestamp
let mut best_height = start;
let mut best_ts = timestamps.collect_one_at(start).unwrap();
let mut best_ts = ts_cursor.get(start).unwrap();
for h in (start + 1)..=max_height_usize {
let block_ts = timestamps.collect_one_at(h).unwrap();
let block_ts = ts_cursor.get(h).unwrap();
if block_ts <= target {
best_height = h;
best_ts = block_ts;
@@ -49,7 +49,7 @@ impl Query {
// Check one block before start in case we need to go backward
if start > 0 && best_ts > target {
let prev_ts = timestamps.collect_one_at(start - 1).unwrap();
let prev_ts = ts_cursor.get(start - 1).unwrap();
if prev_ts <= target {
best_height = start - 1;
best_ts = prev_ts;
+4 -2
View File
@@ -91,6 +91,8 @@ impl Query {
let output_type_reader = indexer.vecs.outputs.output_type.reader();
let type_index_reader = indexer.vecs.outputs.type_index.reader();
let addr_readers = indexer.vecs.addrs.addr_readers();
let blockhash_reader = indexer.vecs.blocks.blockhash.reader();
let mut block_ts_cursor = indexer.vecs.blocks.timestamp.cursor();
let mut cached_block: Option<(Height, BlockHash, Timestamp)> = None;
@@ -113,8 +115,8 @@ impl Query {
{
(bh.clone(), bt)
} else {
let bh = indexer.vecs.blocks.blockhash.read_once(height)?;
let bt = indexer.vecs.blocks.timestamp.collect_one(height).unwrap();
let bh = blockhash_reader.get(height.to_usize());
let bt = block_ts_cursor.get(height.to_usize()).unwrap();
cached_block = Some((height, bh.clone(), bt));
(bh, bt)
};