Skip to content

Commit

Permalink
tapdb/universe: fix universe event logging for grouped assets
Browse files Browse the repository at this point in the history
In this commit, we fix the universe event logging for grouped assets. As
is, when we go to insert assets with a group, then the "first" inserted
asset is what's known as the `asset_id` in the `universe_roots` table.
When we go to log a proof insert/sync event, and the even only has an
asset ID, we may end up with a failed query, as only the "first" asset
ID would return the row we want.

In order to fix this, rather than trying to match the asset ID with a
root, we instead find the _leaf_ for that asset ID, then use that to get
the primary key of the universe root via it's foreign key ref.
  • Loading branch information
Roasbeef committed Jun 8, 2023
1 parent c037025 commit ac26377
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 12 deletions.
16 changes: 10 additions & 6 deletions tapdb/sqlc/queries/universe.sql
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,11 @@ SELECT * FROM universe_servers;

-- name: InsertNewSyncEvent :exec
WITH root_asset_id AS (
SELECT id
FROM universe_roots
WHERE asset_id = @asset_id
SELECT leaves.universe_root_id AS id
FROM universe_leaves leaves
JOIN genesis_info_view gen
ON leaves.asset_genesis_id = gen.gen_asset_id
WHERE gen.asset_id = @asset_id
)
INSERT INTO universe_events (
event_type, universe_root_id, event_time
Expand All @@ -99,9 +101,11 @@ INSERT INTO universe_events (

-- name: InsertNewProofEvent :exec
WITH root_asset_id AS (
SELECT id
FROM universe_roots
WHERE asset_id = @asset_id
SELECT leaves.universe_root_id AS id
FROM universe_leaves leaves
JOIN genesis_info_view gen
ON leaves.asset_genesis_id = gen.gen_asset_id
WHERE gen.asset_id = @asset_id
)
INSERT INTO universe_events (
event_type, universe_root_id, event_time
Expand Down
16 changes: 10 additions & 6 deletions tapdb/sqlc/universe.sql.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit ac26377

Please sign in to comment.