From 4ffdc2a7a05ba75ec4c83d1efa65127c3cbe6214 Mon Sep 17 00:00:00 2001 From: Bartek Nowotarski Date: Wed, 31 Aug 2022 17:31:46 +0200 Subject: [PATCH 1/2] services/horizon: Add history_assets to lookup tables reap --- services/horizon/internal/db2/history/main.go | 18 ++++++++++++++++++ .../horizon/internal/db2/history/reap_test.go | 12 +++++++++++- .../db2/schema/60_add_asset_id_indexes.sql | 9 +++++++++ .../horizon/internal/db2/schema/bindata.go | 12 +++++------- 4 files changed, 43 insertions(+), 8 deletions(-) create mode 100644 services/horizon/internal/db2/schema/60_add_asset_id_indexes.sql diff --git a/services/horizon/internal/db2/history/main.go b/services/horizon/internal/db2/history/main.go index 10eb423290..5f50110e2a 100644 --- a/services/horizon/internal/db2/history/main.go +++ b/services/horizon/internal/db2/history/main.go @@ -879,6 +879,24 @@ func (q Q) ReapLookupTables(ctx context.Context, offsets map[string]int64) ( objectField: "history_account_id", }, }, + "history_assets": { + { + name: "history_trades", + objectField: "base_asset_id", + }, + { + name: "history_trades", + objectField: "counter_asset_id", + }, + { + name: "history_trades_60000", + objectField: "base_asset_id", + }, + { + name: "history_trades_60000", + objectField: "counter_asset_id", + }, + }, "history_claimable_balances": { { name: "history_operation_claimable_balances", diff --git a/services/horizon/internal/db2/history/reap_test.go b/services/horizon/internal/db2/history/reap_test.go index 5e62dc606f..88dc69c273 100644 --- a/services/horizon/internal/db2/history/reap_test.go +++ b/services/horizon/internal/db2/history/reap_test.go @@ -22,6 +22,7 @@ func TestReapLookupTables(t *testing.T) { var ( prevLedgers, curLedgers int prevAccounts, curAccounts int + prevAssets, curAssets int prevClaimableBalances, curClaimableBalances int prevLiquidityPools, curLiquidityPools int ) @@ -32,6 +33,8 @@ func TestReapLookupTables(t *testing.T) { tt.Require.NoError(err) err = db.GetRaw(tt.Ctx, &prevAccounts, `SELECT COUNT(*) FROM history_accounts`) tt.Require.NoError(err) + err = db.GetRaw(tt.Ctx, &prevAssets, `SELECT COUNT(*) FROM history_assets`) + tt.Require.NoError(err) err = db.GetRaw(tt.Ctx, &prevClaimableBalances, `SELECT COUNT(*) FROM history_claimable_balances`) tt.Require.NoError(err) err = db.GetRaw(tt.Ctx, &prevLiquidityPools, `SELECT COUNT(*) FROM history_liquidity_pools`) @@ -60,6 +63,8 @@ func TestReapLookupTables(t *testing.T) { tt.Require.NoError(err) err = db.GetRaw(tt.Ctx, &curAccounts, `SELECT COUNT(*) FROM history_accounts`) tt.Require.NoError(err) + err = db.GetRaw(tt.Ctx, &curAssets, `SELECT COUNT(*) FROM history_assets`) + tt.Require.NoError(err) err = db.GetRaw(tt.Ctx, &curClaimableBalances, `SELECT COUNT(*) FROM history_claimable_balances`) tt.Require.NoError(err) err = db.GetRaw(tt.Ctx, &curLiquidityPools, `SELECT COUNT(*) FROM history_liquidity_pools`) @@ -73,6 +78,10 @@ func TestReapLookupTables(t *testing.T) { tt.Assert.Equal(1, curAccounts, "curAccounts") tt.Assert.Equal(int64(24), deletedCount["history_accounts"], `deletedCount["history_accounts"]`) + tt.Assert.Equal(7, prevAssets, "prevAssets") + tt.Assert.Equal(0, curAssets, "curAssets") + tt.Assert.Equal(int64(7), deletedCount["history_assets"], `deletedCount["history_assets"]`) + tt.Assert.Equal(1, prevClaimableBalances, "prevClaimableBalances") tt.Assert.Equal(0, curClaimableBalances, "curClaimableBalances") tt.Assert.Equal(int64(1), deletedCount["history_claimable_balances"], `deletedCount["history_claimable_balances"]`) @@ -81,8 +90,9 @@ func TestReapLookupTables(t *testing.T) { tt.Assert.Equal(0, curLiquidityPools, "curLiquidityPools") tt.Assert.Equal(int64(1), deletedCount["history_liquidity_pools"], `deletedCount["history_liquidity_pools"]`) - tt.Assert.Len(newOffsets, 3) + tt.Assert.Len(newOffsets, 4) tt.Assert.Equal(int64(0), newOffsets["history_accounts"]) + tt.Assert.Equal(int64(0), newOffsets["history_assets"]) tt.Assert.Equal(int64(0), newOffsets["history_claimable_balances"]) tt.Assert.Equal(int64(0), newOffsets["history_liquidity_pools"]) } diff --git a/services/horizon/internal/db2/schema/60_add_asset_id_indexes.sql b/services/horizon/internal/db2/schema/60_add_asset_id_indexes.sql new file mode 100644 index 0000000000..7086c3fede --- /dev/null +++ b/services/horizon/internal/db2/schema/60_add_asset_id_indexes.sql @@ -0,0 +1,9 @@ +-- +migrate Up + +CREATE INDEX "htrd_by_counter_asset" ON history_trades USING btree (counter_asset_id); +CREATE INDEX "htrd_agg_counter_asset" ON history_trades_60000 USING btree (counter_asset_id); + +-- +migrate Down + +DROP INDEX "htrd_by_counter_asset"; +DROP INDEX "htrd_agg_counter_asset"; diff --git a/services/horizon/internal/db2/schema/bindata.go b/services/horizon/internal/db2/schema/bindata.go index 1d6c2b7bde..9b2c6ae6a5 100644 --- a/services/horizon/internal/db2/schema/bindata.go +++ b/services/horizon/internal/db2/schema/bindata.go @@ -1507,13 +1507,11 @@ var _bindata = map[string]func() (*asset, error){ // directory embedded in the file by go-bindata. // For example if you run go-bindata on data/... and data contains the // following hierarchy: -// -// data/ -// foo.txt -// img/ -// a.png -// b.png -// +// data/ +// foo.txt +// img/ +// a.png +// b.png // then AssetDir("data") would return []string{"foo.txt", "img"}, // AssetDir("data/img") would return []string{"a.png", "b.png"}, // AssetDir("foo.txt") and AssetDir("notexist") would return an error, and From 0156099a07bcaed4745a7a02f4f0d2c92c9a5588 Mon Sep 17 00:00:00 2001 From: Bartek Nowotarski Date: Thu, 1 Sep 2022 14:26:00 +0200 Subject: [PATCH 2/2] gofmt --- services/horizon/internal/db2/schema/bindata.go | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/services/horizon/internal/db2/schema/bindata.go b/services/horizon/internal/db2/schema/bindata.go index 9b2c6ae6a5..1d6c2b7bde 100644 --- a/services/horizon/internal/db2/schema/bindata.go +++ b/services/horizon/internal/db2/schema/bindata.go @@ -1507,11 +1507,13 @@ var _bindata = map[string]func() (*asset, error){ // directory embedded in the file by go-bindata. // For example if you run go-bindata on data/... and data contains the // following hierarchy: -// data/ -// foo.txt -// img/ -// a.png -// b.png +// +// data/ +// foo.txt +// img/ +// a.png +// b.png +// // then AssetDir("data") would return []string{"foo.txt", "img"}, // AssetDir("data/img") would return []string{"a.png", "b.png"}, // AssetDir("foo.txt") and AssetDir("notexist") would return an error, and