mirror of
https://github.com/simplex-chat/simplex-chat.git
synced 2026-09-01 20:08:57 +00:00
core: get group history faster (#5562)
* core: get group history faster * revert join, add index (fix test) * fix postgres compilation * fix postgres schema
This commit is contained in:
@@ -124,6 +124,7 @@ import Simplex.Chat.Store.SQLite.Migrations.M20241223_chat_tags
|
||||
import Simplex.Chat.Store.SQLite.Migrations.M20241230_reports
|
||||
import Simplex.Chat.Store.SQLite.Migrations.M20250105_indexes
|
||||
import Simplex.Chat.Store.SQLite.Migrations.M20250115_chat_ttl
|
||||
import Simplex.Chat.Store.SQLite.Migrations.M20250122_chat_items_include_in_history
|
||||
import Simplex.Messaging.Agent.Store.Shared (Migration (..))
|
||||
|
||||
schemaMigrations :: [(String, Query, Maybe Query)]
|
||||
@@ -247,7 +248,8 @@ schemaMigrations =
|
||||
("20241223_chat_tags", m20241223_chat_tags, Just down_m20241223_chat_tags),
|
||||
("20241230_reports", m20241230_reports, Just down_m20241230_reports),
|
||||
("20250105_indexes", m20250105_indexes, Just down_m20250105_indexes),
|
||||
("20250115_chat_ttl", m20250115_chat_ttl, Just down_m20250115_chat_ttl)
|
||||
("20250115_chat_ttl", m20250115_chat_ttl, Just down_m20250115_chat_ttl),
|
||||
("20250122_chat_items_include_in_history", m20250122_chat_items_include_in_history, Just down_m20250122_chat_items_include_in_history)
|
||||
]
|
||||
|
||||
-- | The list of migrations in ascending order by date
|
||||
|
||||
@@ -0,0 +1,39 @@
|
||||
{-# LANGUAGE QuasiQuotes #-}
|
||||
|
||||
module Simplex.Chat.Store.SQLite.Migrations.M20250122_chat_items_include_in_history where
|
||||
|
||||
import Database.SQLite.Simple (Query)
|
||||
import Database.SQLite.Simple.QQ (sql)
|
||||
|
||||
m20250122_chat_items_include_in_history :: Query
|
||||
m20250122_chat_items_include_in_history =
|
||||
[sql|
|
||||
ALTER TABLE chat_items ADD COLUMN include_in_history INTEGER NOT NULL DEFAULT 0;
|
||||
|
||||
CREATE INDEX idx_chat_items_groups_history ON chat_items(
|
||||
user_id,
|
||||
group_id,
|
||||
include_in_history,
|
||||
item_deleted,
|
||||
item_ts,
|
||||
chat_item_id
|
||||
);
|
||||
|
||||
UPDATE chat_items
|
||||
SET include_in_history = 1
|
||||
WHERE group_id IS NOT NULL
|
||||
AND item_content_tag IN ('rcvMsgContent', 'sndMsgContent')
|
||||
AND msg_content_tag NOT IN ('report');
|
||||
|
||||
CREATE INDEX idx_group_snd_item_statuses_chat_item_id_group_member_id ON group_snd_item_statuses(chat_item_id, group_member_id);
|
||||
|]
|
||||
|
||||
down_m20250122_chat_items_include_in_history :: Query
|
||||
down_m20250122_chat_items_include_in_history =
|
||||
[sql|
|
||||
DROP INDEX idx_group_snd_item_statuses_chat_item_id_group_member_id;
|
||||
|
||||
DROP INDEX idx_chat_items_groups_history;
|
||||
|
||||
ALTER TABLE chat_items DROP COLUMN include_in_history;
|
||||
|]
|
||||
@@ -406,7 +406,8 @@ CREATE TABLE chat_items(
|
||||
fwd_from_group_id INTEGER REFERENCES groups ON DELETE SET NULL,
|
||||
fwd_from_chat_item_id INTEGER REFERENCES chat_items ON DELETE SET NULL,
|
||||
via_proxy INTEGER,
|
||||
msg_content_tag TEXT
|
||||
msg_content_tag TEXT,
|
||||
include_in_history INTEGER NOT NULL DEFAULT 0
|
||||
);
|
||||
CREATE TABLE sqlite_sequence(name,seq);
|
||||
CREATE TABLE chat_item_messages(
|
||||
@@ -978,3 +979,15 @@ CREATE INDEX idx_chat_items_groups_msg_content_tag_deleted ON chat_items(
|
||||
item_deleted,
|
||||
item_sent
|
||||
);
|
||||
CREATE INDEX idx_chat_items_groups_history ON chat_items(
|
||||
user_id,
|
||||
group_id,
|
||||
include_in_history,
|
||||
item_deleted,
|
||||
item_ts,
|
||||
chat_item_id
|
||||
);
|
||||
CREATE INDEX idx_group_snd_item_statuses_chat_item_id_group_member_id ON group_snd_item_statuses(
|
||||
chat_item_id,
|
||||
group_member_id
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user