mirror of
https://github.com/mempool/mempool.git
synced 2026-08-13 12:33:11 +02:00
fix: use actual indexed block count for X-total-count header
This commit is contained in:
parent
abd8defcbb
commit
a0e74fcf9e
2 changed files with 17 additions and 3 deletions
|
|
@ -1176,16 +1176,18 @@ class BitcoinRoutes {
|
||||||
const op = (req.params.op) as 'and' | 'or' | 'nor' | undefined;
|
const op = (req.params.op) as 'and' | 'or' | 'nor' | undefined;
|
||||||
const mask = BigInt(req.params.mask ?? 0n);
|
const mask = BigInt(req.params.mask ?? 0n);
|
||||||
|
|
||||||
const { tip } = await FlagValueRepository.$getTipAndTailIndexedByBucketSize(bucketSize) || { tip: undefined };
|
const { tip, tail } = await FlagValueRepository.$getTipAndTailIndexedByBucketSize(bucketSize) || { tip: undefined, tail: undefined };
|
||||||
|
|
||||||
if (!tip) {
|
if (tip === undefined || tail === undefined) {
|
||||||
handleError(req, res, 400, `Failed to get latest indexed flag values for ${interval}`);
|
handleError(req, res, 400, `Failed to get latest indexed flag values for ${interval}`);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const totalCount = await FlagValueRepository.$getTotalBlocksIndexedByBucketSize(bucketSize === 1 ? 1008 : bucketSize) ?? tip - tail;
|
||||||
|
|
||||||
const startHeight = presets[interval].retentionSpan !== -1 ? (tip - presets[interval].retentionSpan) : -1;
|
const startHeight = presets[interval].retentionSpan !== -1 ? (tip - presets[interval].retentionSpan) : -1;
|
||||||
const txsCount = await FlagValueRepository.$queryTxCountBasedOnMask(mask, bucketSize, op, startHeight);
|
const txsCount = await FlagValueRepository.$queryTxCountBasedOnMask(mask, bucketSize, op, startHeight);
|
||||||
res.header('X-total-count', tip.toString());
|
res.header('X-total-count', totalCount.toString());
|
||||||
res.header('Expires', new Date(Date.now() + 1000 * 3600 * 24 * (presets[interval].bucketSizes[0] / 144)).toUTCString());
|
res.header('Expires', new Date(Date.now() + 1000 * 3600 * 24 * (presets[interval].bucketSizes[0] / 144)).toUTCString());
|
||||||
res.send(txsCount);
|
res.send(txsCount);
|
||||||
} catch (e: any) {
|
} catch (e: any) {
|
||||||
|
|
|
||||||
|
|
@ -128,6 +128,18 @@ class FlagValuesRepository {
|
||||||
logger.err(`Cannot delete flag values above ${height}. Reason: ` + (e instanceof Error ? e.message : e));
|
logger.err(`Cannot delete flag values above ${height}. Reason: ` + (e instanceof Error ? e.message : e));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public async $getTotalBlocksIndexedByBucketSize(bucketSize: number): Promise<number | null> {
|
||||||
|
try {
|
||||||
|
const [rows]: any[] = await DB.query(`SELECT (count(distinct start_height) * ?) as total FROM flag_values WHERE bucket_size = ?`, [bucketSize, bucketSize.toString()]);
|
||||||
|
if (rows !== null && rows.length > 0) {
|
||||||
|
return rows[0].total;
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
logger.err(`Cannot get total blocks indexed in flag_values. Reason: ` + (e instanceof Error ? e.message : e));
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export default new FlagValuesRepository();
|
export default new FlagValuesRepository();
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue