Skip to content

Commit

Permalink
lock pre-existing rows
Browse files Browse the repository at this point in the history
  • Loading branch information
tamirms committed Aug 13, 2024
1 parent a39f734 commit 9ad40ad
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions services/horizon/internal/db2/history/account_loader.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ func bulkGetOrCreate(ctx context.Context, q *Q, table string, fields []columnVal
}

columns := strings.Join(insertFieldsPart, ",")
preExistingRowsSuffix := "ORDER BY id ASC FOR KEY SHARE"
sql := `
WITH rows AS
(SELECT ` + strings.Join(unnestPart, ",") + `),
Expand All @@ -175,11 +176,14 @@ func bulkGetOrCreate(ctx context.Context, q *Q, table string, fields []columnVal
SELECT * FROM rows
ON CONFLICT (` + columns + `) DO NOTHING
RETURNING *
),
pre_existing_rows AS (
SELECT * FROM ` + table + ` WHERE (` + columns + `) IN
(SELECT * FROM rows) ` + preExistingRowsSuffix + `
)
SELECT * FROM inserted_rows
UNION ALL
SELECT * FROM ` + table + ` WHERE (` + columns + `) IN
(SELECT * FROM rows)`
SELECT * FROM pre_existing_rows`

return q.SelectRaw(

Check failure on line 188 in services/horizon/internal/db2/history/account_loader.go

View workflow job for this annotation

GitHub Actions / golangci

q.SelectRaw undefined (type *Q has no field or method SelectRaw) (typecheck)
ctx,
Expand Down

0 comments on commit 9ad40ad

Please sign in to comment.