Skip to content

Commit

Permalink
Order by descending created_at slot & fallback to transaction index w…
Browse files Browse the repository at this point in the history
…hen equal.
  • Loading branch information
KtorZ committed Sep 28, 2022
1 parent 5534043 commit 7770590
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 6 deletions.
6 changes: 6 additions & 0 deletions db/v2.1.0/001.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
DELETE FROM inputs;
DELETE FROM checkpoints;
DELETE FROM binary_data;
DELETE FROM scripts;

CREATE INDEX IF NOT EXISTS inputsByCreatedAt ON inputs(created_at, substr(output_reference, 34, -2));
3 changes: 2 additions & 1 deletion kupo.cabal

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

2 changes: 1 addition & 1 deletion package.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
_config: !include ".hpack.config.yaml"

name: kupo
version: 2.0.0
version: 2.1.0-rc1
stability: stable
github: "cardanosolutions/kupo"
license: MPL-2.0
Expand Down
13 changes: 9 additions & 4 deletions src/Kupo/App/Database.hs
Original file line number Diff line number Diff line change
Expand Up @@ -350,14 +350,18 @@ mkDatabase tr longestRollback bracketConnection = Database
changes conn

, foldInputs = \whereClause yield -> ReaderT $ \conn -> do
let qry = "SELECT output_reference, address, value, datum_hash, script_hash,\
\ created_at, createdAt.header_hash,\
\ spent_at, spentAt.header_hash \
-- TODO: Move upward and make configurable by users.
let ordering = "DESC"
let qry = "SELECT output_reference, address, value, datum_hash, script_hash ,\
\created_at, createdAt.header_hash, \
\spent_at, spentAt.header_hash \
\FROM inputs \
\JOIN checkpoints AS createdAt ON createdAt.slot_no = created_at \
\LEFT OUTER JOIN checkpoints AS spentAt ON spentAt.slot_no = spent_at \
\WHERE " <> whereClause <> " \
\ORDER BY created_at DESC"
\ORDER BY \
\created_at " <> ordering <> ", \
\substr(output_reference, 34, -2) " <> ordering

-- TODO: Allow resolving datums / scripts on demand through LEFT JOIN
--
Expand Down Expand Up @@ -654,6 +658,7 @@ migrations =
, $(embedFile "db/v1.0.0/002.sql")
, $(embedFile "db/v1.0.1/001.sql")
, $(embedFile "db/v2.0.0-beta/001.sql")
, $(embedFile "db/v2.1.0/001.sql")
]
]
where
Expand Down

0 comments on commit 7770590

Please sign in to comment.