Skip to content

Node.js based forum software built for the modern web

feat: migration of old topic thumbs to new format

Julian Lam74d73313fd14
diff --git a/src/upgrades/1.16.0/migrate_thumbs.js b/src/upgrades/1.16.0/migrate_thumbs.js
new file mode 100644
index 0000000000..b5ebd4c5cc
--- /dev/null
+++ b/src/upgrades/1.16.0/migrate_thumbs.js
@@ -0,0 +1,40 @@
+'use strict';
+
+const nconf = require('nconf');
+
+const db = require('../../database');
+const meta = require('../../meta');
+const topics = require('../../topics');
+const batch = require('../../batch');
+
+module.exports = {
+ name: 'Migrate existing topic thumbnails to new format',
+ timestamp: Date.UTC(2020, 11, 11),
+ method: async function () {
+ const progress = this.progress;
+ const current = await meta.configs.get('topicThumbSize');
+
+ if (parseInt(current, 10) === 120) {
+ await meta.configs.set('topicThumbSize', 512);
+ }
+ await meta.configs.set('allowTopicsThumbnail', 1);
+
+ await batch.processSortedSet('topics:tid', async function (tids) {
+ const keys = tids.map(tid => `topic:${tid}`);
+ const topicThumbs = (await db.getObjectsFields(keys, ['thumb'])).map(obj => (obj.thumb ? obj.thumb.replace(nconf.get('upload_url'), '') : null));
+
+ await Promise.all(tids.map(async (tid, idx) => {
+ const path = topicThumbs[idx];
+ if (path) {
+ await topics.thumbs.associate({ id: tid, path });
+ await db.deleteObjectField(keys[idx], 'thumb');
+ }
+
+ progress.incr();
+ }));
+ }, {
+ batch: 500,
+ progress: progress,
+ });
+ },
+};
diff --git a/src/upgrades/1.16.0/topic_thumbs_settings.js b/src/upgrades/1.16.0/topic_thumbs_settings.js
deleted file mode 100644
index 27fa964780..0000000000
--- a/src/upgrades/1.16.0/topic_thumbs_settings.js
+++ /dev/null
@@ -1,16 +0,0 @@
-'use strict';
-
-const meta = require('../../meta');
-
-module.exports = {
- name: 'Config changes for new topic thumbnails',
- timestamp: Date.UTC(2020, 11, 8),
- method: async () => {
- const current = await meta.configs.get('topicThumbSize');
-
- if (parseInt(current, 10) === 120) {
- await meta.configs.set('topicThumbSize', 512);
- }
- await meta.configs.set('allowTopicsThumbnail', 1);
- },
-};