mirror of
https://github.com/yu-i-i/overleaf-cep.git
synced 2026-11-14 22:23:42 +01:00
Merge pull request #1037 from sharelatex/as-decaffeinate
Decaffeinate frontend GitOrigin-RevId: 1c8c53dedecfe55f9936a13408df17b852f996de
This commit is contained in:
committed by
sharelatex
parent
4842a45d8c
commit
659242b457
@@ -3,21 +3,23 @@ const { db } = mongojs
|
||||
const async = require('async')
|
||||
const minilist = require('minimist')
|
||||
|
||||
const updateUser = function (user, callback) {
|
||||
const updateUser = function(user, callback) {
|
||||
console.log(`Updating user ${user._id}`)
|
||||
const update = {
|
||||
$set: {
|
||||
emails: [{
|
||||
email: user.email,
|
||||
createdAt: new Date()
|
||||
}]
|
||||
emails: [
|
||||
{
|
||||
email: user.email,
|
||||
createdAt: new Date()
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
db.users.update({_id: user._id}, update, callback)
|
||||
db.users.update({ _id: user._id }, update, callback)
|
||||
}
|
||||
|
||||
const updateUsers = (users, callback) =>
|
||||
async.eachLimit(users, ASYNC_LIMIT, updateUser, function (error) {
|
||||
async.eachLimit(users, ASYNC_LIMIT, updateUser, function(error) {
|
||||
if (error) {
|
||||
callback(error)
|
||||
return
|
||||
@@ -28,33 +30,34 @@ const updateUsers = (users, 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)
|
||||
})
|
||||
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 }
|
||||
loopForUsers(function(error) {
|
||||
if (error) {
|
||||
throw error
|
||||
}
|
||||
process.exit()
|
||||
})
|
||||
|
||||
let FETCH_LIMIT, ASYNC_LIMIT
|
||||
var setup = function () {
|
||||
var setup = function() {
|
||||
let args = minilist(process.argv.slice(2))
|
||||
FETCH_LIMIT = (args.fetch) ? args.fetch : 100
|
||||
ASYNC_LIMIT = (args.async) ? args.async : 10
|
||||
FETCH_LIMIT = args.fetch ? args.fetch : 100
|
||||
ASYNC_LIMIT = args.async ? args.async : 10
|
||||
}
|
||||
|
||||
setup()
|
||||
|
||||
@@ -4,23 +4,27 @@ const async = require('async')
|
||||
const minilist = require('minimist')
|
||||
|
||||
const newTimeout = 240
|
||||
const oldTimeoutLimits = {$gt: 60, $lt: 240}
|
||||
const oldTimeoutLimits = { $gt: 60, $lt: 240 }
|
||||
|
||||
const updateUser = function (user, callback) {
|
||||
const updateUser = function(user, callback) {
|
||||
console.log(`Updating user ${user._id}`)
|
||||
const update = {
|
||||
$set: {
|
||||
'features.compileTimeout': newTimeout
|
||||
}
|
||||
}
|
||||
db.users.update({
|
||||
_id: user._id,
|
||||
'features.compileTimeout': oldTimeoutLimits
|
||||
}, update, callback)
|
||||
db.users.update(
|
||||
{
|
||||
_id: user._id,
|
||||
'features.compileTimeout': oldTimeoutLimits
|
||||
},
|
||||
update,
|
||||
callback
|
||||
)
|
||||
}
|
||||
|
||||
const updateUsers = (users, callback) =>
|
||||
async.eachLimit(users, ASYNC_LIMIT, updateUser, function (error) {
|
||||
async.eachLimit(users, ASYNC_LIMIT, updateUser, function(error) {
|
||||
if (error) {
|
||||
callback(error)
|
||||
return
|
||||
@@ -36,35 +40,39 @@ const updateUsers = (users, callback) =>
|
||||
})
|
||||
|
||||
var loopForUsers = callback =>
|
||||
db.users.find(
|
||||
{ 'features.compileTimeout': oldTimeoutLimits },
|
||||
{ 'features.compileTimeout': 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)
|
||||
})
|
||||
db.users
|
||||
.find(
|
||||
{ 'features.compileTimeout': oldTimeoutLimits },
|
||||
{ 'features.compileTimeout': 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 }
|
||||
loopForUsers(function(error) {
|
||||
if (error) {
|
||||
throw error
|
||||
}
|
||||
process.exit()
|
||||
})
|
||||
|
||||
let FETCH_LIMIT, ASYNC_LIMIT, DO_ALL
|
||||
var setup = function () {
|
||||
var setup = function() {
|
||||
let args = minilist(process.argv.slice(2))
|
||||
// --fetch N get N users each time
|
||||
FETCH_LIMIT = (args.fetch) ? args.fetch : 100
|
||||
FETCH_LIMIT = args.fetch ? args.fetch : 100
|
||||
// --async M run M updates in parallel
|
||||
ASYNC_LIMIT = (args.async) ? args.async : 10
|
||||
ASYNC_LIMIT = args.async ? args.async : 10
|
||||
// --all means run to completion
|
||||
if (args.all) {
|
||||
if (args.fetch) {
|
||||
|
||||
@@ -1,15 +1,11 @@
|
||||
const {db} = require('../app/js/infrastructure/mongojs')
|
||||
const FeaturesUpdater = require(
|
||||
'../app/js/Features/Subscription/FeaturesUpdater'
|
||||
)
|
||||
const V1SubscriptionManager = require(
|
||||
'../app/js/Features/Subscription/V1SubscriptionManager'
|
||||
)
|
||||
const { db } = require('../app/js/infrastructure/mongojs')
|
||||
const FeaturesUpdater = require('../app/js/Features/Subscription/FeaturesUpdater')
|
||||
const V1SubscriptionManager = require('../app/js/Features/Subscription/V1SubscriptionManager')
|
||||
const async = require('async')
|
||||
const logger = require('logger-sharelatex')
|
||||
logger.logger.level('error')
|
||||
|
||||
const areFeaturesEqual = function (featuresA, featuresB) {
|
||||
const areFeaturesEqual = function(featuresA, featuresB) {
|
||||
for (const feature in featuresA) {
|
||||
if (featuresA[feature] !== featuresB[feature]) {
|
||||
return false
|
||||
@@ -21,44 +17,55 @@ const areFeaturesEqual = function (featuresA, featuresB) {
|
||||
var outOfSyncUserCount = 0
|
||||
var userCount = null
|
||||
|
||||
db.users.find({
|
||||
'overleaf.id': { $exists: true }
|
||||
}, {
|
||||
overleaf: 1,
|
||||
features: 1
|
||||
}, function (error, users) {
|
||||
if (error) throw error
|
||||
console.log('USER COUNT', userCount = users.length)
|
||||
async.mapSeries(users, function (user, callback) {
|
||||
console.log('REFRESHING IN v2', user._id)
|
||||
FeaturesUpdater.refreshFeatures(user._id, false, function (error) {
|
||||
if (error) console.error('ERROR', error)
|
||||
console.log('REFRESHING IN v1', user._id)
|
||||
V1SubscriptionManager.notifyV1OfFeaturesChange(
|
||||
user._id,
|
||||
function (error) {
|
||||
if (error) console.error('ERROR', error)
|
||||
db.users.find({
|
||||
_id: user._id
|
||||
}, {
|
||||
features: 1
|
||||
}, function (error, [updatedUser]) {
|
||||
if (error) throw error
|
||||
if (areFeaturesEqual(user.features, updatedUser.features)) {
|
||||
console.log('UNCHANGED', user._id)
|
||||
} else {
|
||||
console.log('MODIFIED', user._id)
|
||||
outOfSyncUserCount = outOfSyncUserCount + 1
|
||||
}
|
||||
callback()
|
||||
})
|
||||
}
|
||||
)
|
||||
})
|
||||
}, function (error) {
|
||||
db.users.find(
|
||||
{
|
||||
'overleaf.id': { $exists: true }
|
||||
},
|
||||
{
|
||||
overleaf: 1,
|
||||
features: 1
|
||||
},
|
||||
function(error, users) {
|
||||
if (error) throw error
|
||||
console.log('FINISHED!')
|
||||
console.log('OUT OF SYNC USERS', outOfSyncUserCount, '/', userCount)
|
||||
process.exit()
|
||||
})
|
||||
})
|
||||
console.log('USER COUNT', (userCount = users.length))
|
||||
async.mapSeries(
|
||||
users,
|
||||
function(user, callback) {
|
||||
console.log('REFRESHING IN v2', user._id)
|
||||
FeaturesUpdater.refreshFeatures(user._id, false, function(error) {
|
||||
if (error) console.error('ERROR', error)
|
||||
console.log('REFRESHING IN v1', user._id)
|
||||
V1SubscriptionManager.notifyV1OfFeaturesChange(user._id, function(
|
||||
error
|
||||
) {
|
||||
if (error) console.error('ERROR', error)
|
||||
db.users.find(
|
||||
{
|
||||
_id: user._id
|
||||
},
|
||||
{
|
||||
features: 1
|
||||
},
|
||||
function(error, [updatedUser]) {
|
||||
if (error) throw error
|
||||
if (areFeaturesEqual(user.features, updatedUser.features)) {
|
||||
console.log('UNCHANGED', user._id)
|
||||
} else {
|
||||
console.log('MODIFIED', user._id)
|
||||
outOfSyncUserCount = outOfSyncUserCount + 1
|
||||
}
|
||||
callback()
|
||||
}
|
||||
)
|
||||
})
|
||||
})
|
||||
},
|
||||
function(error) {
|
||||
if (error) throw error
|
||||
console.log('FINISHED!')
|
||||
console.log('OUT OF SYNC USERS', outOfSyncUserCount, '/', userCount)
|
||||
process.exit()
|
||||
}
|
||||
)
|
||||
}
|
||||
)
|
||||
|
||||
@@ -1,12 +1,10 @@
|
||||
const InstitutionsManager = require(
|
||||
'../app/js/Features/Institutions/InstitutionsManager'
|
||||
)
|
||||
const InstitutionsManager = require('../app/js/Features/Institutions/InstitutionsManager')
|
||||
|
||||
const institutionId = parseInt(process.argv[2])
|
||||
if (isNaN(institutionId)) throw new Error('No institution id')
|
||||
console.log('Upgrading users of institution', institutionId)
|
||||
|
||||
InstitutionsManager.upgradeInstitutionUsers(institutionId, function (error) {
|
||||
InstitutionsManager.upgradeInstitutionUsers(institutionId, function(error) {
|
||||
if (error) {
|
||||
console.log(error)
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user