From b6bcc092ed9191811bab7dccb0f055f711d2865f Mon Sep 17 00:00:00 2001 From: Richard Hansen Date: Fri, 8 Apr 2022 04:37:15 -0400 Subject: [PATCH] chat: Move message deletion to `padRemove` hook --- src/ep.json | 1 + src/node/chat.js | 8 ++++++++ src/node/db/Pad.js | 5 ----- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/src/ep.json b/src/ep.json index f1c4ad3cd..7c76b4dd7 100644 --- a/src/ep.json +++ b/src/ep.json @@ -28,6 +28,7 @@ "padCheck": "ep_etherpad-lite/node/chat", "padCopy": "ep_etherpad-lite/node/chat", "padLoad": "ep_etherpad-lite/node/chat", + "padRemove": "ep_etherpad-lite/node/chat", "socketio": "ep_etherpad-lite/node/chat" } }, diff --git a/src/node/chat.js b/src/node/chat.js index 570c4aff4..62f0f0fb3 100644 --- a/src/node/chat.js +++ b/src/node/chat.js @@ -173,6 +173,14 @@ exports.padLoad = async (hookName, {pad}) => { if (!('chatHead' in pad)) pad.chatHead = -1; }; +exports.padRemove = async (hookName, {pad}) => { + const ops = (function* () { + const {chatHead = -1} = pad; + for (let i = 0; i <= chatHead; ++i) yield pad.db.remove(`pad:${pad.id}:chat:${i}`); + })(); + for (const op of new Stream(ops).batch(100).buffer(99)) await op; +}; + exports.socketio = (hookName, {io}) => { socketio = io; }; diff --git a/src/node/db/Pad.js b/src/node/db/Pad.js index b16cf8de8..35052a00e 100644 --- a/src/node/db/Pad.js +++ b/src/node/db/Pad.js @@ -530,11 +530,6 @@ class Pad { })); p.push(db.remove(`pad2readonly:${padID}`)); - // delete all chat messages - p.push(promises.timesLimit(this.chatHead + 1, 500, async (i) => { - await this.db.remove(`pad:${this.id}:chat:${i}`, null); - })); - // delete all revisions p.push(promises.timesLimit(this.head + 1, 500, async (i) => { await this.db.remove(`pad:${this.id}:revs:${i}`, null);