@@ -346,7 +346,7 @@ export class PgStore extends BasePgStore {
346
346
} [ ]
347
347
> `
348
348
WITH signer_data AS (
349
- -- Fetch the signer for the given cycle
349
+ -- Fetch the specific signer for the given cycle
350
350
SELECT
351
351
rss.signer_key,
352
352
rss.signer_weight,
@@ -356,39 +356,28 @@ export class PgStore extends BasePgStore {
356
356
AND rss.signer_key = ${ normalizeHexString ( signerId ) }
357
357
),
358
358
proposal_data AS (
359
- -- Fetch the first (oldest) proposal for each block_hash for the given cycle
359
+ -- Select all proposals for the given cycle
360
360
SELECT
361
361
bp.block_hash,
362
362
bp.block_height,
363
363
bp.received_at AS proposal_received_at
364
364
FROM block_proposals bp
365
365
WHERE bp.reward_cycle = ${ cycleNumber }
366
- AND bp.id = (
367
- -- Select the earliest proposal for each block_hash
368
- SELECT MIN(sub_bp.id)
369
- FROM block_proposals sub_bp
370
- WHERE sub_bp.block_hash = bp.block_hash
371
- )
372
366
),
373
367
response_data AS (
374
- -- Fetch the first (oldest) response for each (signer_key, signer_sighash) pair
375
- SELECT DISTINCT ON (br.signer_key, br.signer_sighash)
368
+ -- Select all responses for the proposals in the given cycle
369
+ SELECT
376
370
br.signer_key,
377
371
br.signer_sighash,
378
372
br.accepted,
379
373
br.received_at,
380
374
br.id
381
375
FROM block_responses br
382
- WHERE br.id = (
383
- -- Select the earliest response for each signer_sighash and signer_key
384
- SELECT MIN(sub_br.id)
385
- FROM block_responses sub_br
386
- WHERE sub_br.signer_key = br.signer_key
387
- AND sub_br.signer_sighash = br.signer_sighash
388
- )
376
+ JOIN proposal_data pd ON br.signer_sighash = pd.block_hash
377
+ WHERE br.signer_key = ${ normalizeHexString ( signerId ) } -- Filter for the specific signer
389
378
),
390
379
signer_proposal_data AS (
391
- -- Cross join signers with proposals and left join filtered responses
380
+ -- Cross join the specific signer with proposals and left join filtered responses
392
381
SELECT
393
382
sd.signer_key,
394
383
pd.block_hash,
@@ -397,13 +386,13 @@ export class PgStore extends BasePgStore {
397
386
rd.received_at AS response_received_at,
398
387
EXTRACT(MILLISECOND FROM (rd.received_at - pd.proposal_received_at)) AS response_time_ms
399
388
FROM signer_data sd
400
- CROSS JOIN proposal_data pd -- Cross join to associate all signers with all proposals
389
+ CROSS JOIN proposal_data pd
401
390
LEFT JOIN response_data rd
402
391
ON pd.block_hash = rd.signer_sighash
403
392
AND sd.signer_key = rd.signer_key -- Match signers with their corresponding responses
404
393
),
405
394
aggregated_data AS (
406
- -- Aggregate the proposal and response data by signer
395
+ -- Aggregate the proposal and response data for the specific signer
407
396
SELECT
408
397
spd.signer_key,
409
398
COUNT(CASE WHEN spd.accepted = true THEN 1 END)::integer AS proposals_accepted_count,
0 commit comments