feat: migration of old topic thumbs to new format

closes #9099
v1.18.x
Julian Lam 4 years ago
parent 378a3a6945
commit 74d73313fd

@ -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,
});
},
};

@ -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);
},
};
Loading…
Cancel
Save