Improve performance of Delete All Data
This commit is contained in:
parent
cc13350d3f
commit
1f7386d7cf
2 changed files with 20 additions and 0 deletions
|
@ -5515,6 +5515,9 @@ async function removeAll(): Promise<void> {
|
|||
|
||||
db.transaction(() => {
|
||||
db.exec(`
|
||||
--- Remove messages delete trigger for performance
|
||||
DROP TRIGGER messages_on_delete;
|
||||
|
||||
DELETE FROM attachment_downloads;
|
||||
DELETE FROM badgeImageFiles;
|
||||
DELETE FROM badges;
|
||||
|
@ -5546,6 +5549,21 @@ async function removeAll(): Promise<void> {
|
|||
DELETE FROM uninstalled_sticker_packs;
|
||||
|
||||
INSERT INTO messages_fts(messages_fts) VALUES('optimize');
|
||||
|
||||
--- Re-create the messages delete trigger
|
||||
--- See migration 45
|
||||
CREATE TRIGGER messages_on_delete AFTER DELETE ON messages BEGIN
|
||||
DELETE FROM messages_fts WHERE rowid = old.rowid;
|
||||
DELETE FROM sendLogPayloads WHERE id IN (
|
||||
SELECT payloadId FROM sendLogMessageIds
|
||||
WHERE messageId = old.id
|
||||
);
|
||||
DELETE FROM reactions WHERE rowid IN (
|
||||
SELECT rowid FROM reactions
|
||||
WHERE messageId = old.id
|
||||
);
|
||||
DELETE FROM storyReads WHERE storyId = old.storyId;
|
||||
END;
|
||||
`);
|
||||
})();
|
||||
}
|
||||
|
|
|
@ -75,6 +75,8 @@ export default function updateToSchemaVersion45(
|
|||
|
||||
--- Update delete trigger to remove storyReads
|
||||
|
||||
--- Note: for future updates to this trigger, be sure to update Server.ts/removeAll()
|
||||
--- (it deletes and re-adds this trigger for performance)
|
||||
DROP TRIGGER messages_on_delete;
|
||||
CREATE TRIGGER messages_on_delete AFTER DELETE ON messages BEGIN
|
||||
DELETE FROM messages_fts WHERE rowid = old.rowid;
|
||||
|
|
Loading…
Reference in a new issue