core: fix deletion queries for PostgreSQL client (#5969)

* core: fix deletion queries for PostgreSQL client

* disable test in posrgres

* plan
This commit is contained in:
Evgeny 2025-06-08 18:27:42 +01:00 committed by GitHub
parent ea1a81fcac
commit 50dfda6c09
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 14 additions and 5 deletions

View file

@ -171,7 +171,7 @@ import Simplex.Messaging.Crypto.File (CryptoFile (..), CryptoFileArgs (..))
import Simplex.Messaging.Util (eitherToMaybe) import Simplex.Messaging.Util (eitherToMaybe)
import UnliftIO.STM import UnliftIO.STM
#if defined(dbPostgres) #if defined(dbPostgres)
import Database.PostgreSQL.Simple (FromRow, Only (..), Query, ToRow, (:.) (..)) import Database.PostgreSQL.Simple (FromRow, In (..), Only (..), Query, ToRow, (:.) (..))
import Database.PostgreSQL.Simple.SqlQQ (sql) import Database.PostgreSQL.Simple.SqlQQ (sql)
#else #else
import Database.SQLite.Simple (FromRow, Only (..), Query, ToRow, (:.) (..)) import Database.SQLite.Simple (FromRow, Only (..), Query, ToRow, (:.) (..))
@ -2370,8 +2370,14 @@ updateGroupChatItemModerated db User {userId} GroupInfo {groupId} ci m@GroupMemb
updateMemberCIsModerated :: MsgDirectionI d => DB.Connection -> User -> GroupInfo -> GroupMember -> GroupMember -> SMsgDirection d -> UTCTime -> IO () updateMemberCIsModerated :: MsgDirectionI d => DB.Connection -> User -> GroupInfo -> GroupMember -> GroupMember -> SMsgDirection d -> UTCTime -> IO ()
updateMemberCIsModerated db User {userId} GroupInfo {groupId, membership} member byGroupMember md deletedTs = do updateMemberCIsModerated db User {userId} GroupInfo {groupId, membership} member byGroupMember md deletedTs = do
itemIds <- updateCIs =<< getCurrentTime itemIds <- updateCIs =<< getCurrentTime
#if defined(dbPostgres)
let inItemIds = Only $ In (map fromOnly itemIds)
DB.execute db "DELETE FROM messages WHERE message_id IN (SELECT message_id FROM chat_item_messages WHERE chat_item_id IN ?)" inItemIds
DB.execute db "DELETE FROM chat_item_versions WHERE chat_item_id IN ?" inItemIds
#else
DB.executeMany db deleteChatItemMessagesQuery itemIds DB.executeMany db deleteChatItemMessagesQuery itemIds
DB.executeMany db "DELETE FROM chat_item_versions WHERE chat_item_id = ?" itemIds DB.executeMany db "DELETE FROM chat_item_versions WHERE chat_item_id = ?" itemIds
#endif
where where
memId = groupMemberId' member memId = groupMemberId' member
updateQuery = updateQuery =
@ -2887,7 +2893,7 @@ getGroupCIMentions db ciId =
SELECT r.display_name, r.member_id, m.group_member_id, m.member_role, p.display_name, p.local_alias SELECT r.display_name, r.member_id, m.group_member_id, m.member_role, p.display_name, p.local_alias
FROM chat_item_mentions r FROM chat_item_mentions r
LEFT JOIN group_members m ON r.group_id = m.group_id AND r.member_id = m.member_id LEFT JOIN group_members m ON r.group_id = m.group_id AND r.member_id = m.member_id
LEFT JOIN contact_profiles p ON p.contact_profile_id = COALESCE(m.member_profile_id, m.contact_profile_id) LEFT JOIN contact_profiles p ON p.contact_profile_id = COALESCE(m.member_profile_id, m.contact_profile_id)
WHERE r.chat_item_id = ? WHERE r.chat_item_id = ?
|] |]
(Only ciId) (Only ciId)

View file

@ -3186,7 +3186,7 @@ Query:
SELECT r.display_name, r.member_id, m.group_member_id, m.member_role, p.display_name, p.local_alias SELECT r.display_name, r.member_id, m.group_member_id, m.member_role, p.display_name, p.local_alias
FROM chat_item_mentions r FROM chat_item_mentions r
LEFT JOIN group_members m ON r.group_id = m.group_id AND r.member_id = m.member_id LEFT JOIN group_members m ON r.group_id = m.group_id AND r.member_id = m.member_id
LEFT JOIN contact_profiles p ON p.contact_profile_id = COALESCE(m.member_profile_id, m.contact_profile_id) LEFT JOIN contact_profiles p ON p.contact_profile_id = COALESCE(m.member_profile_id, m.contact_profile_id)
WHERE r.chat_item_id = ? WHERE r.chat_item_id = ?
Plan: Plan:

View file

@ -84,7 +84,10 @@ chatGroupTests = do
describe "batch send messages" $ do describe "batch send messages" $ do
it "send multiple messages api" testSendMulti it "send multiple messages api" testSendMulti
it "send multiple timed messages" testSendMultiTimed it "send multiple timed messages" testSendMultiTimed
#if !defined(dbPostgres)
-- TODO [postgres] this test hangs with PostgreSQL
it "send multiple messages (many chat batches)" testSendMultiManyBatches it "send multiple messages (many chat batches)" testSendMultiManyBatches
#endif
xit'' "shared message body is reused" testSharedMessageBody xit'' "shared message body is reused" testSharedMessageBody
xit'' "shared batch body is reused" testSharedBatchBody xit'' "shared batch body is reused" testSharedBatchBody
describe "async group connections" $ do describe "async group connections" $ do
@ -1821,7 +1824,7 @@ testDeleteMemberWithMessages =
do do
cath <## "alice updated group #team:" cath <## "alice updated group #team:"
cath <## "updated group preferences:" cath <## "updated group preferences:"
cath <## "Full deletion: on" cath <## "Full deletion: on"
] ]
threadDelay 750000 threadDelay 750000
bob #> "#team hello" bob #> "#team hello"
@ -6496,7 +6499,7 @@ testForwardQuoteMention =
bob <## " hello @alice @cath", bob <## " hello @alice @cath",
do do
cath <# "#team alice!> -> forwarded" cath <# "#team alice!> -> forwarded"
cath <## " hello @alice @cath" cath <## " hello @alice @cath"
] ]
-- forward mentions -- forward mentions
alice `send` "@bob <- #team hello" alice `send` "@bob <- #team hello"