diff options
| author | syuilo <syuilotan@yahoo.co.jp> | 2018-05-06 18:04:37 +0900 |
|---|---|---|
| committer | syuilo <syuilotan@yahoo.co.jp> | 2018-05-06 18:04:37 +0900 |
| commit | 3f2a7a561ee7e008422d4cac3b269beb6006072a (patch) | |
| tree | e3ba00363cf0bdef063b392b7e400c689d15ba98 /migration | |
| parent | Fix (diff) | |
| download | sharkey-3f2a7a561ee7e008422d4cac3b269beb6006072a.tar.gz sharkey-3f2a7a561ee7e008422d4cac3b269beb6006072a.tar.bz2 sharkey-3f2a7a561ee7e008422d4cac3b269beb6006072a.zip | |
アイコンのレンダリングを改善
Diffstat (limited to 'migration')
| -rw-r--r-- | migration/2.4.0.js | 69 |
1 files changed, 69 insertions, 0 deletions
diff --git a/migration/2.4.0.js b/migration/2.4.0.js new file mode 100644 index 0000000000..d324d4471e --- /dev/null +++ b/migration/2.4.0.js @@ -0,0 +1,69 @@ +// for Node.js interpret + +const chalk = require('chalk'); +const sequential = require('promise-sequential'); + +const { default: User } = require('../built/models/user'); +const { default: DriveFile } = require('../built/models/drive-file'); + +async function main() { + const promiseGens = []; + + const count = await User.count({}); + + let prev; + + for (let i = 0; i < count; i++) { + promiseGens.push(() => { + const promise = new Promise(async (res, rej) => { + const user = await User.findOne(prev ? { + _id: { $gt: prev._id } + } : {}, { + sort: { + _id: 1 + } + }); + + prev = user; + + const set = {}; + + if (user.avatarId != null) { + const file = await DriveFile.findOne({ _id: user.avatarId }); + + if (file && file.metadata.properties.avgColor) { + set.avatarColor = file.metadata.properties.avgColor; + } + } + + if (user.bannerId != null) { + const file = await DriveFile.findOne({ _id: user.bannerId }); + + if (file && file.metadata.properties.avgColor) { + set.bannerColor = file.metadata.properties.avgColor; + } + } + + User.update({ + _id: user._id + }, { + $set: set + }).then(() => { + res([i, user]); + }).catch(rej); + }); + + promise.then(([i, user]) => { + console.log(chalk`{gray ${i}} {green done: {bold ${user._id}} @${user.username}}`); + }); + + return promise; + }); + } + + return await sequential(promiseGens); +} + +main().then(() => { + console.log('ALL DONE'); +}).catch(console.error); |