Skip to content

Commit

Permalink
Merge pull request #464 from 4miners/427_quickfix
Browse files Browse the repository at this point in the history
Fix performance of aggregateBlocksReward SQL query - Closes #427
  • Loading branch information
karmacoma committed Mar 7, 2017
2 parents 22b3174 + c749593 commit 8eaab90
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions sql/blocks.js
Expand Up @@ -31,16 +31,16 @@ var BlocksSql = {
'delegate AS (SELECT',
'1 FROM mem_accounts m WHERE m."isDelegate" = 1 AND m."publicKey" = DECODE (${generatorPublicKey}, \'hex\') LIMIT 1),',
'borders AS (SELECT',
'(SELECT CEIL(b.height / ${delegates}::float) FROM blocks b ORDER BY b.height DESC LIMIT 1) AS current,',
'(SELECT CEIL(b.height / ${delegates}::float) FROM blocks b',
'(SELECT CEIL(b.height / ${delegates}::float)::bigint FROM blocks b ORDER BY b.height DESC LIMIT 1) AS current,',
'(SELECT CEIL(b.height / ${delegates}::float)::bigint FROM blocks b',
(params.start !== undefined ? ' WHERE b.timestamp >= ${start}' : ''),
'ORDER BY b.height ASC LIMIT 1) AS min,',
'(SELECT CEIL(b.height / ${delegates}::float) FROM blocks b',
'(SELECT CEIL(b.height / ${delegates}::float)::bigint FROM blocks b',
(params.end !== undefined ? ' WHERE b.timestamp <= ${end}' : ''),
'ORDER BY b.height DESC LIMIT 1) AS max',
'),',
'r AS (SELECT DISTINCT ',
'CEIL(b.height / ${delegates}::float) AS round',
'CEIL(b.height / ${delegates}::float)::bigint AS round',
'FROM blocks b WHERE b."generatorPublicKey" = DECODE (${generatorPublicKey}, \'hex\')),',
're AS (SELECT r.round AS round, ((r.round-1)*${delegates})+1 AS min, r.round*${delegates} AS max',
'FROM r WHERE r.round >= (SELECT min FROM borders) AND round <= (SELECT max FROM borders)),',
Expand Down

0 comments on commit 8eaab90

Please sign in to comment.