diff --git a/apps/simplex-store-service/src/StoreService/Names/Records.hs b/apps/simplex-store-service/src/StoreService/Names/Records.hs index 3e31741c04..2a1bc17eb7 100644 --- a/apps/simplex-store-service/src/StoreService/Names/Records.hs +++ b/apps/simplex-store-service/src/StoreService/Names/Records.hs @@ -1,4 +1,3 @@ -{-# LANGUAGE CPP #-} {-# LANGUAGE LambdaCase #-} {-# LANGUAGE NamedFieldPuns #-} {-# LANGUAGE OverloadedStrings #-} @@ -48,12 +47,6 @@ import StoreService.Names.Sender (SendError (..), Sender, submitTransaction) import StoreService.Names.Store import StoreService.Names.Turns (Turns, withLabelTurn) -#if defined(dbPostgres) -import Database.PostgreSQL.Simple (Only (..)) -#else -import Database.SQLite.Simple (Only (..)) -#endif - data Records = Records { rsStore :: DBStore, rsTurns :: Turns, @@ -368,16 +361,3 @@ signatureExpired = revertText RNSignatureExpired withStore :: Records -> (DB.Connection -> IO a) -> IO a withStore Records {rsStore} = withTransaction rsStore - -pendingEditIds :: DB.Connection -> IO [Int64] -pendingEditIds db = map fromOnly <$> DB.query db "SELECT name_record_edit_id FROM sx_badge_service_name_record_edits WHERE state = ? ORDER BY name_record_edit_id" (Only pendingState) - -deleteUnsentEdit :: DB.Connection -> Int64 -> IO () -deleteUnsentEdit db editId = - DB.execute - db - "DELETE FROM sx_badge_service_name_record_edits WHERE name_record_edit_id = ? AND state = ? AND NOT EXISTS (SELECT 1 FROM sx_badge_service_name_transactions WHERE name_record_edit_id = ?)" - (editId, pendingState, editId) - -pendingState :: Text -pendingState = "pending" diff --git a/apps/simplex-store-service/src/StoreService/Names/Store.hs b/apps/simplex-store-service/src/StoreService/Names/Store.hs index 76bdfca27a..c243398c0a 100644 --- a/apps/simplex-store-service/src/StoreService/Names/Store.hs +++ b/apps/simplex-store-service/src/StoreService/Names/Store.hs @@ -64,6 +64,8 @@ module StoreService.Names.Store getRecordEditByBody, getRecordEditByNonce, settleRecordEdit, + pendingEditIds, + deleteUnsentEdit, relayedEditTimes, ) where @@ -922,6 +924,16 @@ settleRecordEdit db editId state = ESMined tx -> (minedEdit, Nothing, tx) ESReverted name -> (revertedEdit, name, Nothing) +pendingEditIds :: DB.Connection -> IO [Int64] +pendingEditIds db = map fromOnly <$> DB.query db "SELECT name_record_edit_id FROM sx_badge_service_name_record_edits WHERE state = ? ORDER BY name_record_edit_id" (Only pendingEdit) + +deleteUnsentEdit :: DB.Connection -> Int64 -> IO () +deleteUnsentEdit db editId = + DB.execute + db + "DELETE FROM sx_badge_service_name_record_edits WHERE name_record_edit_id = ? AND state = ? AND NOT EXISTS (SELECT 1 FROM sx_badge_service_name_transactions WHERE name_record_edit_id = ?)" + (editId, pendingEdit, editId) + -- | When each edit relayed for the name since the given time was sent, oldest first. relayedEditTimes :: DB.Connection -> LabelHash -> UTCTime -> IO [UTCTime] relayedEditTimes db (LabelHash lh) since =