mirror of
https://git.joinsharkey.org/Sharkey/Sharkey.git
synced 2024-12-23 09:03:08 +02:00
wip
This commit is contained in:
parent
8fd78aebbf
commit
11e05a3a32
2 changed files with 72 additions and 1 deletions
|
@ -215,7 +215,11 @@ module.exports = (params, user: IUser, app) => new Promise(async (res, rej) => {
|
|||
poll: poll,
|
||||
text: text,
|
||||
user_id: user._id,
|
||||
app_id: app ? app._id : null
|
||||
app_id: app ? app._id : null,
|
||||
|
||||
// 以下非正規化データ
|
||||
_reply: reply ? { user_id: reply.user_id } : undefined,
|
||||
_repost: repost ? { user_id: repost.user_id } : undefined,
|
||||
});
|
||||
|
||||
// Serialize
|
||||
|
|
67
tools/migration/node.2017-12-22.hiseikika.js
Normal file
67
tools/migration/node.2017-12-22.hiseikika.js
Normal file
|
@ -0,0 +1,67 @@
|
|||
// for Node.js interpret
|
||||
|
||||
const { default: Post } = require('../../built/api/models/post')
|
||||
const { default: zip } = require('@prezzemolo/zip')
|
||||
|
||||
const migrate = async (post) => {
|
||||
const x = {};
|
||||
if (post.reply_id != null) {
|
||||
const reply = await Post.findOne({
|
||||
_id: post.reply_id
|
||||
});
|
||||
x['_reply.user_id'] = reply.user_id;
|
||||
}
|
||||
if (post.repost_id != null) {
|
||||
const repost = await Post.findOne({
|
||||
_id: post.repost_id
|
||||
});
|
||||
x['_repost.user_id'] = repost.user_id;
|
||||
}
|
||||
if (post.reply_id != null || post.repost_id != null) {
|
||||
const result = await Post.update(post._id, {
|
||||
$set: x,
|
||||
});
|
||||
return result.ok === 1;
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
async function main() {
|
||||
const query = {
|
||||
$or: [{
|
||||
reply_id: {
|
||||
$exists: true,
|
||||
$ne: null
|
||||
}
|
||||
}, {
|
||||
repost_id: {
|
||||
$exists: true,
|
||||
$ne: null
|
||||
}
|
||||
}]
|
||||
}
|
||||
|
||||
const count = await Post.count(query);
|
||||
|
||||
const dop = Number.parseInt(process.argv[2]) || 5
|
||||
const idop = ((count - (count % dop)) / dop) + 1
|
||||
|
||||
return zip(
|
||||
1,
|
||||
async (time) => {
|
||||
console.log(`${time} / ${idop}`)
|
||||
const doc = await Post.find(query, {
|
||||
limit: dop, skip: time * dop
|
||||
})
|
||||
return Promise.all(doc.map(migrate))
|
||||
},
|
||||
idop
|
||||
).then(a => {
|
||||
const rv = []
|
||||
a.forEach(e => rv.push(...e))
|
||||
return rv
|
||||
})
|
||||
}
|
||||
|
||||
main().then(console.dir).catch(console.error)
|
Loading…
Reference in a new issue