Skip to content

Commit

Permalink
Minor fixes in cache
Browse files Browse the repository at this point in the history
  • Loading branch information
rdlrt committed Mar 14, 2024
1 parent 664c2b7 commit d6abc09
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
14 changes: 7 additions & 7 deletions files/grest/rpc/01_cached_tables/pool_history_cache.sql
Original file line number Diff line number Diff line change
Expand Up @@ -44,16 +44,16 @@ BEGIN
RAISE EXCEPTION 'Active stake cache not yet populated! Exiting...';
END IF;

SELECT COALESCE(MAX(epoch_no), 0) INTO _latest_epoch_no_in_cache FROM grest.pool_history_cache;
-- Split into 100 epochs at a time to avoid hours spent on a single query (which can be risky if that query is killed)
SELECT LEAST( 500 , (MAX(no) - _latest_epoch_no_in_cache) ) + _latest_epoch_no_in_cache ) INTO _curr_epoch FROM epoch;

IF _epoch_no_to_insert_from IS NULL THEN
SELECT COALESCE(MAX(epoch_no), 0) INTO _latest_epoch_no_in_cache
FROM grest.pool_history_cache;
IF _latest_epoch_no_in_cache = 0 THEN
RAISE NOTICE 'Pool history cache table is empty, starting initial population...';
PERFORM grest.pool_history_cache_update (0);
RETURN;
END IF;
SELECT MAX(no) INTO _curr_epoch
FROM epoch;
-- no-op IF we already have data up until second most recent epoch
IF _latest_epoch_no_in_cache >= (_curr_epoch - 1) THEN
INSERT INTO grest.control_table (key, last_value)
Expand All @@ -68,15 +68,15 @@ BEGIN
-- purge the data for the given epoch range, in theory should do nothing IF invoked only at start of new epoch
DELETE FROM grest.pool_history_cache
WHERE epoch_no >= _epoch_no_to_insert_from;

INSERT INTO grest.pool_history_cache (
WITH
blockcounts AS (
SELECT
sl.pool_hash_id,
b.epoch_no,
COUNT(*) AS block_cnt
FROM
block AS b,
FROM block AS b,
slot_leader AS sl
WHERE b.slot_leader_id = sl.id
AND b.epoch_no >= _epoch_no_to_insert_from
Expand Down Expand Up @@ -239,7 +239,7 @@ BEGIN
END
END AS epoch_ros
FROM pool_hash AS ph
INNER JOIN activeandfees AS actf ON actf.pool_id = ph."view"
INNER JOIN activeandfees AS actf ON actf.pool_id = ph.view
LEFT JOIN blockcounts AS b ON ph.id = b.pool_hash_id
AND actf.epoch_no = b.epoch_no
LEFT JOIN leadertotals AS l ON ph.id = l.pool_id
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ BEGIN
account_delta_instant_rewards AS (
SELECT
awdp.stake_address_id,
COALESCE(SUM(ir.amount), 0) AS rewards
COALESCE(SUM(ir.amount), 0) AS amount
FROM instant_reward AS ir
INNER JOIN accounts_with_delegated_pools AS awdp ON awdp.stake_address_id = ir.addr_id
WHERE ir.spendable_epoch >= (_active_stake_epoch + 2)
Expand Down

0 comments on commit d6abc09

Please sign in to comment.