mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-21 20:47:08 -05:00
018a44eeb5
[misc] normalize mongo imports GitOrigin-RevId: ac653d9982e0d36736b90f4c03d4c00be88ea76a
63 lines
1.4 KiB
JavaScript
63 lines
1.4 KiB
JavaScript
const { db } = require('../app/src/infrastructure/mongojs')
|
|
const async = require('async')
|
|
const minilist = require('minimist')
|
|
|
|
const updateUser = function(user, callback) {
|
|
console.log(`Updating user ${user._id}`)
|
|
const update = {
|
|
$set: {
|
|
emails: [
|
|
{
|
|
email: user.email,
|
|
createdAt: new Date()
|
|
}
|
|
]
|
|
}
|
|
}
|
|
db.users.update({ _id: user._id }, update, callback)
|
|
}
|
|
|
|
const updateUsers = (users, callback) =>
|
|
async.eachLimit(users, ASYNC_LIMIT, updateUser, function(error) {
|
|
if (error) {
|
|
callback(error)
|
|
return
|
|
}
|
|
counter += users.length
|
|
console.log(`${counter} users updated`)
|
|
loopForUsers(callback)
|
|
})
|
|
|
|
var loopForUsers = callback =>
|
|
db.users
|
|
.find({ emails: { $exists: false } }, { email: 1 })
|
|
.limit(FETCH_LIMIT, function(error, users) {
|
|
if (error) {
|
|
callback(error)
|
|
return
|
|
}
|
|
if (users.length === 0) {
|
|
console.log(`DONE (${counter} users updated)`)
|
|
return callback()
|
|
}
|
|
updateUsers(users, callback)
|
|
})
|
|
|
|
var counter = 0
|
|
var run = () =>
|
|
loopForUsers(function(error) {
|
|
if (error) {
|
|
throw error
|
|
}
|
|
process.exit()
|
|
})
|
|
|
|
let FETCH_LIMIT, ASYNC_LIMIT
|
|
var setup = function() {
|
|
let args = minilist(process.argv.slice(2))
|
|
FETCH_LIMIT = args.fetch ? args.fetch : 100
|
|
ASYNC_LIMIT = args.async ? args.async : 10
|
|
}
|
|
|
|
setup()
|
|
run()
|