Skip to content

Node.js based forum software built for the modern web

refactor(posts): remove superfluous removeFromQueueByTid method

Julian Lame3fa2fb1dcf4
diff --git a/src/posts/queue.js b/src/posts/queue.js
index 5c8a4d164b..585a9d09d7 100644
--- a/src/posts/queue.js
+++ b/src/posts/queue.js
@@ -341,26 +341,6 @@ module.exports = function (Posts) {
}
}
- Posts.removeFromQueueByTid = async function (tid) {
- // todo: refactor this to be more general (search by different values in queue hash or hash.data)
- const tids = Array.isArray(tid) ? tid : [tid];
- const ids = await db.getSortedSetRange('post:queue', 0, -1);
- if (!ids.length) {
- return [];
- }
- const keys = ids.map(id => `post:queue:${id}`);
- const items = await db.getObjects(keys);
- const toRemove = [];
- items.forEach((item, idx) => {
- const data = JSON.parse(item.data);
- if (tids.includes(String(data.tid))) {
- toRemove.push(ids[idx]);
- }
- });
- await Promise.all(toRemove.map(removeFromQueue));
- return toRemove;
- };
-
Posts.removeFromQueue = async function (id) {
const data = await getParsedObject(id);
if (!data) {
diff --git a/src/topics/delete.js b/src/topics/delete.js
index f900f054d6..2016c6ce57 100644
--- a/src/topics/delete.js
+++ b/src/topics/delete.js
@@ -30,7 +30,8 @@ module.exports = function (Topics) {
resolveTopicPostFlags(pids, uid),
activitypub.out.remove.context(uid, tid),
categories.updateRecentTidForCid(cid),
- posts.removeFromQueueByTid(tid),
+ posts.getQueuedPosts({ tid }).then(items =>
+ Promise.all(items.map(item => posts.removeFromQueue(item.id)))),
]);
};
@@ -134,7 +135,8 @@ module.exports = function (Topics) {
deleteFromTags(deletedTopics),
Topics.events.purge(tidsToDelete),
Topics.crossposts.removeAll(tidsToDelete),
- posts.removeFromQueueByTid(tidsToDelete),
+ posts.getQueuedPosts({ tid: tidsToDelete }).then(items =>
+ Promise.all(items.map(item => posts.removeFromQueue(item.id)))),
reduceCounters(deletedTopics),
]);