Skip to content

Commit

Permalink
(BIDS-2457) remove previous odao members (#2540)
Browse files Browse the repository at this point in the history
* (BIDS-2457) remove previous odao members

* use pq.ByteaArray

Co-authored-by: Stefan Pletka <[email protected]>

* (BIDS-2457) added missing import

---------

Co-authored-by: Stefan Pletka <[email protected]>
  • Loading branch information
remoterami and Eisei24 authored Sep 21, 2023
1 parent ef0762d commit 30ea844
Showing 1 changed file with 30 additions and 1 deletion.
31 changes: 30 additions & 1 deletion exporter/rocketpool.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
_ "github.com/jackc/pgx/v4/stdlib"
"github.com/jmoiron/sqlx"
"github.com/klauspost/compress/zstd"
"github.com/lib/pq"
rpDAO "github.com/rocket-pool/rocketpool-go/dao"
rpDAOTrustedNode "github.com/rocket-pool/rocketpool-go/dao/trustednode"
"github.com/rocket-pool/rocketpool-go/minipool"
Expand Down Expand Up @@ -1117,6 +1118,7 @@ func (rp *RocketpoolExporter) SaveDAOMembers() error {

valueStrings := make([]string, 0, batchSize)
valueArgs := make([]interface{}, 0, batchSize*nArgs)
addresses := make([][]byte, 0, batchSize)
for i, d := range data[start:end] {
for j := 0; j < nArgs; j++ {
valueStringsArgs[j] = i*nArgs + j + 1
Expand All @@ -1130,12 +1132,39 @@ func (rp *RocketpoolExporter) SaveDAOMembers() error {
valueArgs = append(valueArgs, d.LastProposalTime)
valueArgs = append(valueArgs, d.RPLBondAmount.String())
valueArgs = append(valueArgs, d.UnbondedValidatorCount)
addresses = append(addresses, d.Address)
}
stmt := fmt.Sprintf(`insert into rocketpool_dao_members (rocketpool_storage_address, address, id, url, joined_time, last_proposal_time, rpl_bond_amount, unbonded_validator_count) values %s on conflict (rocketpool_storage_address, address) do update set id = excluded.id, url = excluded.url, joined_time = excluded.joined_time, last_proposal_time = excluded.last_proposal_time, rpl_bond_amount = excluded.rpl_bond_amount, unbonded_validator_count = excluded.unbonded_validator_count`, strings.Join(valueStrings, ","))
stmt := fmt.Sprintf(`
INSERT INTO rocketpool_dao_members (
rocketpool_storage_address,
address,
id,
url,
joined_time,
last_proposal_time,
rpl_bond_amount,
unbonded_validator_count
)
values %s
on conflict (rocketpool_storage_address, address) do update set
id = excluded.id,
url = excluded.url,
joined_time = excluded.joined_time,
last_proposal_time = excluded.last_proposal_time,
rpl_bond_amount = excluded.rpl_bond_amount,
unbonded_validator_count = excluded.unbonded_validator_count
`, strings.Join(valueStrings, ","))
_, err := tx.Exec(stmt, valueArgs...)
if err != nil {
return fmt.Errorf("error inserting into rocketpool_dao_members: %w", err)
}

_, err = tx.Exec(`
DELETE FROM rocketpool_dao_members
WHERE NOT address = ANY($1)`, pq.ByteaArray(addresses))
if err != nil {
return fmt.Errorf("error deleting from rocketpool_dao_members: %w", err)
}
}

return tx.Commit()
Expand Down

0 comments on commit 30ea844

Please sign in to comment.