Skip to content

Commit

Permalink
Merge pull request #478 from Concordium/fix-block-metric-future-bucket
Browse files Browse the repository at this point in the history
Fix date_bin_series to not include bucket in future
  • Loading branch information
limemloh authored Feb 7, 2025
2 parents f98931c + bed7026 commit d943fbe
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
1 change: 1 addition & 0 deletions backend-rust/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ Database schema version: 2
- Contract rejected event skips in the correct way.
- Fix issue where `ContractUpdated::message` attempted to parse empty messages, resulting in parsing error messages instead of `null`.
- Issue making `avgFinalizationTime` field of `Query::block_metrics` always return `null`.
- Issue making `Query::block_metrics` included a bucket for a period in the future.

## [0.1.19] - 2025-01-30

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,18 @@ ALTER TABLE blocks ALTER COLUMN hash SET DATA TYPE VARCHAR(64);
CREATE INDEX blocks_hash_gin_trgm_idx ON blocks USING gin(hash gin_trgm_ops);
-- Important for quickly calculating the delegated stake to a baker pool.
CREATE INDEX delegated_target_baker_id_index ON accounts(delegated_target_baker_id);
-- Function for generating a table where each row is a bucket.
-- Used by metrics queries.
-- This is replacing the current `date_bin_series` in a backwards compatible way, fixing issue where
-- a future bucket always got included.
CREATE OR REPLACE FUNCTION date_bin_series(bucket_size interval, starting TIMESTAMPTZ, ending TIMESTAMPTZ)
RETURNS TABLE(bucket_start TIMESTAMPTZ, bucket_end TIMESTAMPTZ) AS $$
SELECT
bucket_start,
bucket_start + bucket_size
FROM generate_series(
date_bin(bucket_size, starting, TIMESTAMPTZ '2001-01-01'),
date_bin(bucket_size, ending, TIMESTAMPTZ '2001-01-01'),
bucket_size
) as bucket_start;
$$ LANGUAGE sql;

0 comments on commit d943fbe

Please sign in to comment.