Skip to content

Commit

Permalink
Merge pull request #293 from input-output-hk/rvl/154/sqlite-indexes
Browse files Browse the repository at this point in the history
Add indexes to certain SQLite table columns
  • Loading branch information
paweljakubas committed May 21, 2019
2 parents f4f6a2d + eb2798b commit 8c5d985
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
2 changes: 1 addition & 1 deletion lib/core/cardano-wallet-core.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ library
, basement
, bytestring
, cardano-crypto
, conduit
, containers
, cryptonite
, deepseq
Expand All @@ -54,6 +53,7 @@ library
, persistent
, persistent-sqlite
, persistent-template
, resourcet
, servant
, servant-server
, text
Expand Down
19 changes: 17 additions & 2 deletions lib/core/src/Cardano/Wallet/DB/Sqlite.hs
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,14 @@ import Cardano.Wallet.DB.Sqlite.Types
( AddressPoolXPub (..), TxId (..) )
import Cardano.Wallet.Primitive.AddressDerivation
( Depth (..), deserializeXPrv, serializeXPrv )
import Conduit
import Control.Monad.Trans.Resource
( runResourceT )
import Control.Concurrent.MVar
( newMVar, withMVar )
import Control.DeepSeq
( NFData )
import Control.Monad
( void )
( void, mapM_ )
import Control.Monad.Catch
( MonadCatch (..), handleJust )
import Control.Monad.IO.Class
Expand Down Expand Up @@ -73,6 +73,7 @@ import Database.Persist.Sql
, insertMany_
, insert_
, putMany
, rawExecute
, runMigration
, runSqlConn
, selectFirst
Expand Down Expand Up @@ -160,6 +161,7 @@ newDBLayer fp = do
lock <- newMVar ()
conn <- createSqliteBackend fp (dbLogs [LevelError])
runQuery conn $ runMigration migrateAll
runQuery conn addIndexes
return $ DBLayer

{-----------------------------------------------------------------------
Expand Down Expand Up @@ -269,6 +271,19 @@ newDBLayer fp = do
ExceptT $ withMVar lock $ \() -> runExceptT action
}

----------------------------------------------------------------------------
-- SQLite database setup

addIndexes :: SqlPersistM ()
addIndexes = mapM_ (`rawExecute` [])
[ createIndex "pending_tx_wallet_id" "pending_tx (wallet_id)"
, createIndex "tx_meta_wallet_id" "tx_meta (wallet_id)"
, createIndex "tx_in_tx_id" "tx_in (tx_id)"
, createIndex "tx_out_tx_id" "tx_out (tx_id)"
]
where
createIndex name on = "CREATE INDEX IF NOT EXISTS " <> name <> " ON " <> on

----------------------------------------------------------------------------
-- Conversion between Persistent table types and wallet types

Expand Down

0 comments on commit 8c5d985

Please sign in to comment.