summaryrefslogtreecommitdiff
path: root/migration
diff options
context:
space:
mode:
authorsyuilo <syuilotan@yahoo.co.jp>2018-04-19 12:43:25 +0900
committersyuilo <syuilotan@yahoo.co.jp>2018-04-19 12:43:25 +0900
commit0d5bc3be6611a6877a71233ac57c0987027c0398 (patch)
tree28c6b736dc870b6de5893ee52b712c20973b7298 /migration
parentMerge pull request #1514 from syuilo/greenkeeper/style-loader-0.21.0 (diff)
downloadsharkey-0d5bc3be6611a6877a71233ac57c0987027c0398.tar.gz
sharkey-0d5bc3be6611a6877a71233ac57c0987027c0398.tar.bz2
sharkey-0d5bc3be6611a6877a71233ac57c0987027c0398.zip
ストーキング実装
Closes #1511
Diffstat (limited to 'migration')
-rw-r--r--migration/2018-04-19.js49
1 files changed, 49 insertions, 0 deletions
diff --git a/migration/2018-04-19.js b/migration/2018-04-19.js
new file mode 100644
index 0000000000..b0df22c009
--- /dev/null
+++ b/migration/2018-04-19.js
@@ -0,0 +1,49 @@
+// for Node.js interpret
+
+const { default: User } = require('../built/models/user');
+const { default: Following } = require('../built/models/following');
+const { default: zip } = require('@prezzemolo/zip')
+
+const migrate = async (following) => {
+ const follower = await User.findOne({ _id: following.followerId });
+ const followee = await User.findOne({ _id: following.followeeId });
+ const result = await Following.update(following._id, {
+ $set: {
+ stalk: true,
+ _follower: {
+ host: follower.host,
+ inbox: follower.host != null ? follower.inbox : undefined
+ },
+ _followee: {
+ host: followee.host,
+ inbox: followee.host != null ? followee.inbox : undefined
+ }
+ }
+ });
+ return result.ok === 1;
+}
+
+async function main() {
+ const count = await Following.count({});
+
+ 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 Following.find({}, {
+ 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)