Skip to content

Node.js based forum software built for the modern web

fix: dont store ap tids in topics:tid

Barış Soner Uşaklıe8ef2e5c5506
diff --git a/src/topics/create.js b/src/topics/create.js
index f1f6fd570e..6b5d7699b8 100644
--- a/src/topics/create.js
+++ b/src/topics/create.js
@@ -57,7 +57,7 @@ module.exports = function (Topics) {
await db.setObject(`topic:${topicData.tid}`, topicData);
const timestampedSortedSetKeys = [
- 'topics:tid',
+ utils.isNumber(tid) ? 'topics:tid' : 'topicsRemote:tid',
`cid:${topicData.cid}:tids`,
`cid:${topicData.cid}:tids:create`,
`cid:${topicData.cid}:uid:${topicData.uid}:tids`,
diff --git a/src/upgrades/4.9.0/topicsRemote_zset.js b/src/upgrades/4.9.0/topicsRemote_zset.js
new file mode 100644
index 0000000000..678b528cff
--- /dev/null
+++ b/src/upgrades/4.9.0/topicsRemote_zset.js
@@ -0,0 +1,28 @@
+'use strict';
+
+const db = require('../../database');
+const batch = require('../../batch');
+const utils = require('../../utils');
+
+module.exports = {
+ name: 'Move ap tids from topics:tid to topicsRemote:tid',
+ timestamp: Date.UTC(2026, 1, 24),
+ method: async function () {
+ const { progress } = this;
+ progress.total = await db.sortedSetCard('topics:tid');
+
+ await batch.processSortedSet('topics:tid', async (topicData) => {
+ const apTopics = topicData.filter(topic => !utils.isNumber(topic.value));
+ await db.sortedSetRemove('topics:tid', apTopics.map(topic => topic.value));
+ await db.sortedSetAdd(
+ 'topicsRemote:tid',
+ apTopics.map(t => t.score),
+ apTopics.map(t => t.value)
+ );
+ progress.incr(topicData.length);
+ }, {
+ batch: 500,
+ withScores: true,
+ });
+ },
+};