Browse Source
In order to speed up the available coins retrieval, the aggregated_amounts table is created, here we store the total available coins which can be retrieved fast.prometheus-integration
Alexis Hernandez
6 years ago
6 changed files with 65 additions and 11 deletions
@ -0,0 +1,22 @@ |
|||
package com.xsn.explorer.data.anorm.dao |
|||
|
|||
import java.sql.Connection |
|||
|
|||
import anorm._ |
|||
|
|||
class AggregatedAmountPostgresDAO { |
|||
|
|||
def updateAvailableCoins(delta: BigDecimal)(implicit conn: Connection): Unit = { |
|||
val affectedRows = SQL( |
|||
""" |
|||
|UPDATE aggregated_amounts |
|||
|SET value = value + {delta} |
|||
|WHERE name = 'available_coins' |
|||
""".stripMargin |
|||
).on( |
|||
'delta -> delta |
|||
).executeUpdate() |
|||
|
|||
require(affectedRows == 1) |
|||
} |
|||
} |
@ -0,0 +1,17 @@ |
|||
|
|||
# --- !Ups |
|||
|
|||
CREATE TABLE aggregated_amounts( |
|||
name TEXT NOT NULL, |
|||
value AMOUNT_TYPE NOT NULL, |
|||
-- constraints |
|||
CONSTRAINT aggregated_amounts_name_pk PRIMARY KEY (name) |
|||
); |
|||
|
|||
INSERT INTO aggregated_amounts |
|||
SELECT 'available_coins' AS name, COALESCE(SUM(received - spent), 0) AS value FROM balances; |
|||
|
|||
|
|||
# --- !Downs |
|||
|
|||
DROP TABLE aggregated_amounts; |
Loading…
Reference in new issue