cleanup
This commit is contained in:
parent
f6dfa3158f
commit
cf57347240
2 changed files with 12 additions and 20 deletions
|
|
@ -94,19 +94,18 @@ pub async fn rebuild_range(
|
|||
let select_sql = r#"
|
||||
WITH per_pool_tx_raw AS (
|
||||
SELECT
|
||||
uf.token_id,
|
||||
phe.token_id,
|
||||
phe.txid,
|
||||
tx.effective_timestamp AS ts,
|
||||
phe.effective_timestamp AS ts,
|
||||
phe.utxo,
|
||||
phe.sats_delta,
|
||||
phe.token_delta,
|
||||
phe.sequence
|
||||
FROM pool_history_entry AS phe
|
||||
JOIN utxo_funding AS uf ON phe.utxo = uf.new_utxo_hash
|
||||
JOIN tx ON tx.txid = phe.txid
|
||||
WHERE tx.blockhash IS NOT NULL
|
||||
AND tx.effective_timestamp >= ?
|
||||
AND tx.effective_timestamp < ?
|
||||
AND phe.effective_timestamp >= ?
|
||||
AND phe.effective_timestamp < ?
|
||||
),
|
||||
per_pool_tx AS (
|
||||
SELECT
|
||||
|
|
|
|||
|
|
@ -233,16 +233,16 @@ async fn fetch_raw_trades(
|
|||
let sql = r#"
|
||||
WITH per_pool_tx_raw AS (
|
||||
SELECT
|
||||
tx.txid,
|
||||
COALESCE(tx.first_seen_timestamp, tx.mtp_timestamp) AS effective_timestamp,
|
||||
phe.txid,
|
||||
phe.effective_timestamp,
|
||||
phe.utxo,
|
||||
phe.sats_delta,
|
||||
phe.token_delta,
|
||||
phe.sequence
|
||||
FROM pool_history_entry AS phe
|
||||
JOIN utxo_funding AS uf ON phe.utxo = uf.new_utxo_hash
|
||||
JOIN tx ON tx.txid = phe.txid
|
||||
WHERE uf.token_id = ?
|
||||
WHERE phe.token_id = ?
|
||||
AND phe.effective_timestamp >= ?
|
||||
AND phe.effective_timestamp < ?
|
||||
),
|
||||
per_pool_tx AS (
|
||||
SELECT
|
||||
|
|
@ -255,7 +255,6 @@ per_pool_tx AS (
|
|||
SUM(ABS(sats_delta)) AS volume_sats_pool,
|
||||
SUM(ABS(token_delta)) AS volume_tokens_pool
|
||||
FROM per_pool_tx_raw
|
||||
WHERE effective_timestamp >= ? AND effective_timestamp < ?
|
||||
GROUP BY txid, effective_timestamp, utxo
|
||||
),
|
||||
tx_trades AS (
|
||||
|
|
@ -318,18 +317,12 @@ pub async fn candlesticks(
|
|||
{
|
||||
let ohlcv_end = ohlcv_materialized_end.min(timestamp_end);
|
||||
|
||||
// Align start to 1-hour bucket boundary for the ohlcv query.
|
||||
let ohlcv_start = timestamp_start / 3600 * 3600;
|
||||
|
||||
// timestamp_start is guaranteed hour-aligned by the entry condition above.
|
||||
let ohlcv_rows =
|
||||
ohlcv::get_active_candles(pool, &token_blob, ohlcv_start, ohlcv_end).await?;
|
||||
ohlcv::get_active_candles(pool, &token_blob, timestamp_start, ohlcv_end).await?;
|
||||
|
||||
let (mut result, found_first, last_close) =
|
||||
fill_ohlcv_candles(ohlcv_rows, ohlcv_start, ohlcv_end, false, None);
|
||||
|
||||
// If the requested start doesn't align to ohlcv_start, trim leading flat candles
|
||||
// that fall before timestamp_start.
|
||||
result.retain(|c| c.time >= timestamp_start);
|
||||
fill_ohlcv_candles(ohlcv_rows, timestamp_start, ohlcv_end, false, None);
|
||||
|
||||
if ohlcv_end < timestamp_end {
|
||||
// Tail: query raw for [ohlcv_end, timestamp_end) and append.
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue