Skip to content

Commit

Permalink
services/horizon: Add history_assets to lookup tables reap (#4565)
Browse files Browse the repository at this point in the history
Adds the last remaining table: `history_assets` to lookup table reaper.

In #4518 the code responsible for reaping lookup tables was added but was
missing one table: `history_assets` due to lack of proper indexes. This commit
should remove all remaining data in lookup tables.
  • Loading branch information
bartekn committed Sep 6, 2022
1 parent 56a707d commit 0f5afa2
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 1 deletion.
18 changes: 18 additions & 0 deletions services/horizon/internal/db2/history/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
12 changes: 11 additions & 1 deletion services/horizon/internal/db2/history/reap_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
Expand All @@ -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`)
Expand Down Expand Up @@ -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`)
Expand All @@ -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"]`)
Expand All @@ -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"])
}
Original file line number Diff line number Diff line change
@@ -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";

0 comments on commit 0f5afa2

Please sign in to comment.