mirror of
https://github.com/simplex-chat/simplex-chat.git
synced 2026-11-04 19:27:55 +00:00
store: keep the record edit queries in the store
This commit is contained in:
1 parent
3d278c0b39
commit
ed82876948
2 files changed
+12
-20
No files matched your search
@@ -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"
|
||||
@@ -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 =
|
||||
|
||||
Reference in new issue
Block a user