Skip to content

Commit

Permalink
Improve performance of owner sanitizing (#220)
Browse files Browse the repository at this point in the history
* Change SQL queries for owner sanitizing

* Remove SQL query comment
  • Loading branch information
awfm9 authored Aug 29, 2022
1 parent 69f8212 commit 4dd7b7a
Showing 1 changed file with 5 additions and 14 deletions.
19 changes: 5 additions & 14 deletions storage/graph/owner_repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,16 +77,10 @@ func (o *OwnerRepository) Upsert(transfers ...*events.Transfer) error {
func (o *OwnerRepository) Sanitize() error {

result, err := o.build.
Select(
"a.owner",
"a.nft_id",
"a.event_id",
"b.event_id",
).
From("owners as a, owners as b").
Where("a.owner = b.owner").
Where("a.nft_id = b.nft_id").
Where("a.number = -b.number").
Select("owner", "nft_id").
From("owners").
GroupBy("owner, nft_id").
Having("SUM(number) = 0").
Query()
if err != nil {
return fmt.Errorf("could not execute query: %w", err)
Expand All @@ -99,12 +93,10 @@ func (o *OwnerRepository) Sanitize() error {
return fmt.Errorf("could not get next row: %w", result.Err())
}

var owner, nftID, eventID1, eventID2 string
var owner, nftID string
err = result.Scan(
&owner,
&nftID,
&eventID1,
&eventID2,
)
if err != nil {
return fmt.Errorf("could not scan next row: %w", err)
Expand All @@ -114,7 +106,6 @@ func (o *OwnerRepository) Sanitize() error {
Delete("owners").
Where("owner = ?", owner).
Where("nft_id = ?", nftID).
Where("(event_id = ? OR event_id = ?)", eventID1, eventID2).
Exec()
if err != nil {
return fmt.Errorf("could not delete rows: %w", err)
Expand Down

0 comments on commit 4dd7b7a

Please sign in to comment.