mirror of
https://github.com/overleaf/overleaf.git
synced 2025-04-08 11:43:11 +00:00
Merge pull request #2372 from overleaf/em-mongo-connection-pool
Use the default Mongoose connection pool for all models GitOrigin-RevId: d227b7eb36f130085c9eb1480dc07bd50ba57768
This commit is contained in:
parent
27504d7b9d
commit
bdc5360bc0
26 changed files with 78 additions and 218 deletions
services/web
app/src
Features/SudoMode
infrastructure
models
DeletedProject.jsDeletedSubscription.jsDeletedUser.jsDoc.jsDocSnapshot.jsFile.jsFolder.jsInstitution.jsOauthAccessToken.jsOauthApplication.jsOauthAuthorizationCode.jsProject.jsProjectHistoryFailure.jsProjectInvite.jsPublisher.jsSamlLog.jsSubscription.jsSystemMessage.jsTeamInvite.jsUser.jsUserStub.js
config
test/unit/src
|
@ -15,7 +15,7 @@ let SudoModeController
|
|||
const logger = require('logger-sharelatex')
|
||||
const SudoModeHandler = require('./SudoModeHandler')
|
||||
const AuthenticationController = require('../Authentication/AuthenticationController')
|
||||
const { ObjectId } = require('../../infrastructure/Mongoose').mongo
|
||||
const { ObjectId } = require('mongodb')
|
||||
const UserGetter = require('../User/UserGetter')
|
||||
const Settings = require('settings-sharelatex')
|
||||
|
||||
|
|
|
@ -1,27 +1,27 @@
|
|||
/* eslint-disable
|
||||
max-len,
|
||||
*/
|
||||
// TODO: This file was created by bulk-decaffeinate.
|
||||
// Fix any style issues and re-enable lint.
|
||||
/*
|
||||
* decaffeinate suggestions:
|
||||
* DS102: Remove unnecessary code created because of implicit returns
|
||||
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
|
||||
*/
|
||||
const mongoose = require('mongoose')
|
||||
const Settings = require('settings-sharelatex')
|
||||
const logger = require('logger-sharelatex')
|
||||
|
||||
const POOL_SIZE = Settings.mongo.poolSize
|
||||
|
||||
mongoose.connect(
|
||||
Settings.mongo.url,
|
||||
{
|
||||
server: { poolSize: 10 },
|
||||
config: { autoIndex: false }
|
||||
poolSize: POOL_SIZE,
|
||||
config: { autoIndex: false },
|
||||
useMongoClient: true,
|
||||
appname: 'web'
|
||||
}
|
||||
)
|
||||
|
||||
mongoose.connection.on('connected', () =>
|
||||
logger.log({ url: Settings.mongo.url }, 'mongoose default connection open')
|
||||
logger.log(
|
||||
{
|
||||
url: Settings.mongo.url,
|
||||
poolSize: POOL_SIZE
|
||||
},
|
||||
'mongoose default connection open'
|
||||
)
|
||||
)
|
||||
|
||||
mongoose.connection.on('error', err =>
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
const mongoose = require('mongoose')
|
||||
const Settings = require('settings-sharelatex')
|
||||
const mongoose = require('../infrastructure/Mongoose')
|
||||
const { ProjectSchema } = require('./Project')
|
||||
|
||||
const { Schema } = mongoose
|
||||
|
@ -30,13 +29,5 @@ const DeletedProjectSchema = new Schema(
|
|||
{ collection: 'deletedProjects' }
|
||||
)
|
||||
|
||||
const conn = mongoose.createConnection(Settings.mongo.url, {
|
||||
server: { poolSize: Settings.mongo.poolSize || 10 },
|
||||
config: { autoIndex: false }
|
||||
})
|
||||
|
||||
const DeletedProject = conn.model('DeletedProject', DeletedProjectSchema)
|
||||
|
||||
mongoose.model('DeletedProject', DeletedProjectSchema)
|
||||
exports.DeletedProject = DeletedProject
|
||||
exports.DeletedProject = mongoose.model('DeletedProject', DeletedProjectSchema)
|
||||
exports.DeletedProjectSchema = DeletedProjectSchema
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
const mongoose = require('mongoose')
|
||||
const Settings = require('settings-sharelatex')
|
||||
const mongoose = require('../infrastructure/Mongoose')
|
||||
const { SubscriptionSchema } = require('./Subscription')
|
||||
|
||||
const { Schema } = mongoose
|
||||
|
@ -27,16 +26,9 @@ const DeletedSubscriptionSchema = new Schema(
|
|||
{ collection: 'deletedSubscriptions' }
|
||||
)
|
||||
|
||||
const conn = mongoose.createConnection(Settings.mongo.url, {
|
||||
server: { poolSize: Settings.mongo.poolSize || 10 },
|
||||
config: { autoIndex: false }
|
||||
})
|
||||
|
||||
const DeletedSubscription = conn.model(
|
||||
exports.DeletedSubscription = mongoose.model(
|
||||
'DeletedSubscription',
|
||||
DeletedSubscriptionSchema
|
||||
)
|
||||
|
||||
mongoose.model('DeletedSubscription', DeletedSubscriptionSchema)
|
||||
exports.DeletedSubscription = DeletedSubscription
|
||||
exports.DeletedSubscriptionSchema = DeletedSubscriptionSchema
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
const mongoose = require('mongoose')
|
||||
const Settings = require('settings-sharelatex')
|
||||
const mongoose = require('../infrastructure/Mongoose')
|
||||
const { UserSchema } = require('./User')
|
||||
|
||||
const { Schema } = mongoose
|
||||
|
@ -27,13 +26,6 @@ const DeletedUserSchema = new Schema(
|
|||
{ collection: 'deletedUsers' }
|
||||
)
|
||||
|
||||
const conn = mongoose.createConnection(Settings.mongo.url, {
|
||||
server: { poolSize: Settings.mongo.poolSize || 10 },
|
||||
config: { autoIndex: false }
|
||||
})
|
||||
exports.DeletedUser = mongoose.model('DeletedUser', DeletedUserSchema)
|
||||
|
||||
const DeletedUser = conn.model('DeletedUser', DeletedUserSchema)
|
||||
|
||||
mongoose.model('DeletedUser', DeletedUserSchema)
|
||||
exports.DeletedUser = DeletedUser
|
||||
exports.DeletedUserSchema = DeletedUserSchema
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
const mongoose = require('mongoose')
|
||||
const mongoose = require('../infrastructure/Mongoose')
|
||||
|
||||
const { Schema } = mongoose
|
||||
|
||||
|
@ -6,6 +6,6 @@ const DocSchema = new Schema({
|
|||
name: { type: String, default: 'new doc' }
|
||||
})
|
||||
|
||||
mongoose.model('Doc', DocSchema)
|
||||
exports.Doc = mongoose.model('Doc')
|
||||
exports.Doc = mongoose.model('Doc', DocSchema)
|
||||
|
||||
exports.DocSchema = DocSchema
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
const mongoose = require('mongoose')
|
||||
const mongoose = require('../infrastructure/Mongoose')
|
||||
|
||||
const { Schema } = mongoose
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
const mongoose = require('mongoose')
|
||||
const mongoose = require('../infrastructure/Mongoose')
|
||||
|
||||
const { Schema } = mongoose
|
||||
|
||||
|
@ -20,6 +20,5 @@ const FileSchema = new Schema({
|
|||
}
|
||||
})
|
||||
|
||||
mongoose.model('File', FileSchema)
|
||||
exports.File = mongoose.model('File')
|
||||
exports.File = mongoose.model('File', FileSchema)
|
||||
exports.FileSchema = FileSchema
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
const mongoose = require('mongoose')
|
||||
const mongoose = require('../infrastructure/Mongoose')
|
||||
const { DocSchema } = require('./Doc')
|
||||
const { FileSchema } = require('./File')
|
||||
|
||||
|
@ -14,6 +14,5 @@ FolderSchema.add({
|
|||
folders: [FolderSchema]
|
||||
})
|
||||
|
||||
mongoose.model('Folder', FolderSchema)
|
||||
exports.Folder = mongoose.model('Folder')
|
||||
exports.Folder = mongoose.model('Folder', FolderSchema)
|
||||
exports.FolderSchema = FolderSchema
|
||||
|
|
|
@ -1,7 +1,4 @@
|
|||
/* eslint-disable
|
||||
handle-callback-err
|
||||
*/
|
||||
const mongoose = require('mongoose')
|
||||
const mongoose = require('../infrastructure/Mongoose')
|
||||
const { Schema } = mongoose
|
||||
const { ObjectId } = Schema
|
||||
const settings = require('settings-sharelatex')
|
||||
|
@ -19,11 +16,8 @@ const InstitutionSchema = new Schema({
|
|||
|
||||
// fetch institution's data from v1 API. Errors are ignored
|
||||
InstitutionSchema.method('fetchV1Data', function(callback) {
|
||||
if (callback == null) {
|
||||
callback = function(error, institution) {}
|
||||
}
|
||||
const url = `${settings.apis.v1.url}/universities/list/${this.v1Id}`
|
||||
return request.get(url, (error, response, body) => {
|
||||
request.get(url, (error, response, body) => {
|
||||
let parsedBody
|
||||
try {
|
||||
parsedBody = JSON.parse(body)
|
||||
|
@ -39,15 +33,9 @@ InstitutionSchema.method('fetchV1Data', function(callback) {
|
|||
this.countryCode = parsedBody != null ? parsedBody.country_code : undefined
|
||||
this.departments = parsedBody != null ? parsedBody.departments : undefined
|
||||
this.portalSlug = parsedBody != null ? parsedBody.portal_slug : undefined
|
||||
return callback(null, this)
|
||||
callback(null, this)
|
||||
})
|
||||
})
|
||||
|
||||
const conn = mongoose.createConnection(settings.mongo.url, {
|
||||
server: { poolSize: settings.mongo.poolSize || 10 },
|
||||
config: { autoIndex: false }
|
||||
})
|
||||
|
||||
const Institution = conn.model('Institution', InstitutionSchema)
|
||||
exports.Institution = Institution
|
||||
exports.Institution = mongoose.model('Institution', InstitutionSchema)
|
||||
exports.InstitutionSchema = InstitutionSchema
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
const mongoose = require('mongoose')
|
||||
const Settings = require('settings-sharelatex')
|
||||
const mongoose = require('../infrastructure/Mongoose')
|
||||
|
||||
const { Schema } = mongoose
|
||||
const { ObjectId } = Schema
|
||||
|
@ -19,13 +18,9 @@ const OauthAccessTokenSchema = new Schema(
|
|||
}
|
||||
)
|
||||
|
||||
const conn = mongoose.createConnection(Settings.mongo.url, {
|
||||
server: { poolSize: Settings.mongo.poolSize || 10 },
|
||||
config: { autoIndex: false }
|
||||
})
|
||||
exports.OauthAccessToken = mongoose.model(
|
||||
'OauthAccessToken',
|
||||
OauthAccessTokenSchema
|
||||
)
|
||||
|
||||
const OauthAccessToken = conn.model('OauthAccessToken', OauthAccessTokenSchema)
|
||||
|
||||
mongoose.model('OauthAccessToken', OauthAccessTokenSchema)
|
||||
exports.OauthAccessToken = OauthAccessToken
|
||||
exports.OauthAccessTokenSchema = OauthAccessTokenSchema
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
const mongoose = require('mongoose')
|
||||
const Settings = require('settings-sharelatex')
|
||||
const mongoose = require('../infrastructure/Mongoose')
|
||||
|
||||
const { Schema } = mongoose
|
||||
|
||||
|
@ -17,13 +16,9 @@ const OauthApplicationSchema = new Schema(
|
|||
}
|
||||
)
|
||||
|
||||
const conn = mongoose.createConnection(Settings.mongo.url, {
|
||||
server: { poolSize: Settings.mongo.poolSize || 10 },
|
||||
config: { autoIndex: false }
|
||||
})
|
||||
exports.OauthApplication = mongoose.model(
|
||||
'OauthApplication',
|
||||
OauthApplicationSchema
|
||||
)
|
||||
|
||||
const OauthApplication = conn.model('OauthApplication', OauthApplicationSchema)
|
||||
|
||||
mongoose.model('OauthApplication', OauthApplicationSchema)
|
||||
exports.OauthApplication = OauthApplication
|
||||
exports.OauthApplicationSchema = OauthApplicationSchema
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
const mongoose = require('mongoose')
|
||||
const Settings = require('settings-sharelatex')
|
||||
const mongoose = require('../infrastructure/Mongoose')
|
||||
|
||||
const { Schema } = mongoose
|
||||
const { ObjectId } = Schema
|
||||
|
@ -18,16 +17,9 @@ const OauthAuthorizationCodeSchema = new Schema(
|
|||
}
|
||||
)
|
||||
|
||||
const conn = mongoose.createConnection(Settings.mongo.url, {
|
||||
server: { poolSize: Settings.mongo.poolSize || 10 },
|
||||
config: { autoIndex: false }
|
||||
})
|
||||
|
||||
const OauthAuthorizationCode = conn.model(
|
||||
exports.OauthAuthorizationCode = mongoose.model(
|
||||
'OauthAuthorizationCode',
|
||||
OauthAuthorizationCodeSchema
|
||||
)
|
||||
|
||||
mongoose.model('OauthAuthorizationCode', OauthAuthorizationCodeSchema)
|
||||
exports.OauthAuthorizationCode = OauthAuthorizationCode
|
||||
exports.OauthAuthorizationCodeSchema = OauthAuthorizationCodeSchema
|
||||
|
|
|
@ -1,10 +1,9 @@
|
|||
const mongoose = require('mongoose')
|
||||
const Settings = require('settings-sharelatex')
|
||||
const mongoose = require('../infrastructure/Mongoose')
|
||||
const _ = require('underscore')
|
||||
const { FolderSchema } = require('./Folder.js')
|
||||
const concreteObjectId = require('mongoose').Types.ObjectId
|
||||
const Errors = require('../Features/Errors/Errors')
|
||||
|
||||
const concreteObjectId = mongoose.Types.ObjectId
|
||||
const { Schema } = mongoose
|
||||
const { ObjectId } = Schema
|
||||
|
||||
|
@ -120,34 +119,22 @@ const ProjectSchema = new Schema({
|
|||
|
||||
ProjectSchema.statics.getProject = function(projectOrId, fields, callback) {
|
||||
if (projectOrId._id != null) {
|
||||
return callback(null, projectOrId)
|
||||
callback(null, projectOrId)
|
||||
} else {
|
||||
try {
|
||||
concreteObjectId(projectOrId.toString())
|
||||
} catch (e) {
|
||||
return callback(new Errors.NotFoundError(e.message))
|
||||
}
|
||||
return this.findById(projectOrId, fields, callback)
|
||||
this.findById(projectOrId, fields, callback)
|
||||
}
|
||||
}
|
||||
|
||||
var applyToAllFilesRecursivly = (ProjectSchema.statics.applyToAllFilesRecursivly = function(
|
||||
folder,
|
||||
fun
|
||||
) {
|
||||
function applyToAllFilesRecursivly(folder, fun) {
|
||||
_.each(folder.fileRefs, file => fun(file))
|
||||
return _.each(folder.folders, folder =>
|
||||
applyToAllFilesRecursivly(folder, fun)
|
||||
)
|
||||
})
|
||||
_.each(folder.folders, folder => applyToAllFilesRecursivly(folder, fun))
|
||||
}
|
||||
ProjectSchema.statics.applyToAllFilesRecursivly = applyToAllFilesRecursivly
|
||||
|
||||
const conn = mongoose.createConnection(Settings.mongo.url, {
|
||||
server: { poolSize: Settings.mongo.poolSize || 10 },
|
||||
config: { autoIndex: false }
|
||||
})
|
||||
|
||||
const Project = conn.model('Project', ProjectSchema)
|
||||
|
||||
mongoose.model('Project', ProjectSchema)
|
||||
exports.Project = Project
|
||||
exports.Project = mongoose.model('Project', ProjectSchema)
|
||||
exports.ProjectSchema = ProjectSchema
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
const mongoose = require('mongoose')
|
||||
const mongoose = require('../infrastructure/Mongoose')
|
||||
|
||||
const { Schema } = mongoose
|
||||
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
const mongoose = require('mongoose')
|
||||
const Settings = require('settings-sharelatex')
|
||||
const mongoose = require('../infrastructure/Mongoose')
|
||||
|
||||
const { Schema } = mongoose
|
||||
const { ObjectId } = Schema
|
||||
|
@ -31,14 +30,6 @@ const ProjectInviteSchema = new Schema(
|
|||
}
|
||||
)
|
||||
|
||||
const conn = mongoose.createConnection(Settings.mongo.url, {
|
||||
server: { poolSize: Settings.mongo.poolSize || 10 },
|
||||
config: { autoIndex: false }
|
||||
})
|
||||
|
||||
const ProjectInvite = conn.model('ProjectInvite', ProjectInviteSchema)
|
||||
|
||||
mongoose.model('ProjectInvite', ProjectInviteSchema)
|
||||
exports.ProjectInvite = ProjectInvite
|
||||
exports.ProjectInvite = mongoose.model('ProjectInvite', ProjectInviteSchema)
|
||||
exports.ProjectInviteSchema = ProjectInviteSchema
|
||||
exports.EXPIRY_IN_SECONDS = EXPIRY_IN_SECONDS
|
||||
|
|
|
@ -1,7 +1,4 @@
|
|||
/* eslint-disable
|
||||
handle-callback-err
|
||||
*/
|
||||
const mongoose = require('mongoose')
|
||||
const mongoose = require('../infrastructure/Mongoose')
|
||||
const { Schema } = mongoose
|
||||
const { ObjectId } = Schema
|
||||
const settings = require('settings-sharelatex')
|
||||
|
@ -15,10 +12,7 @@ const PublisherSchema = new Schema({
|
|||
|
||||
// fetch publisher's (brand on v1) data from v1 API. Errors are ignored
|
||||
PublisherSchema.method('fetchV1Data', function(callback) {
|
||||
if (callback == null) {
|
||||
callback = function(error, publisher) {}
|
||||
}
|
||||
return request(
|
||||
request(
|
||||
{
|
||||
baseUrl: settings.apis.v1.url,
|
||||
url: `/api/v2/brands/${this.slug}`,
|
||||
|
@ -43,16 +37,10 @@ PublisherSchema.method('fetchV1Data', function(callback) {
|
|||
}
|
||||
this.name = parsedBody != null ? parsedBody.name : undefined
|
||||
this.partner = parsedBody != null ? parsedBody.partner : undefined
|
||||
return callback(null, this)
|
||||
callback(null, this)
|
||||
}
|
||||
)
|
||||
})
|
||||
|
||||
const conn = mongoose.createConnection(settings.mongo.url, {
|
||||
server: { poolSize: settings.mongo.poolSize || 10 },
|
||||
config: { autoIndex: false }
|
||||
})
|
||||
|
||||
const Publisher = conn.model('Publisher', PublisherSchema)
|
||||
exports.Publisher = Publisher
|
||||
exports.Publisher = mongoose.model('Publisher', PublisherSchema)
|
||||
exports.PublisherSchema = PublisherSchema
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
const Settings = require('settings-sharelatex')
|
||||
const mongoose = require('mongoose')
|
||||
const mongoose = require('../infrastructure/Mongoose')
|
||||
const { Schema } = mongoose
|
||||
|
||||
const SamlLogSchema = new Schema(
|
||||
|
@ -14,13 +13,5 @@ const SamlLogSchema = new Schema(
|
|||
}
|
||||
)
|
||||
|
||||
const conn = mongoose.createConnection(Settings.mongo.url, {
|
||||
server: { poolSize: Settings.mongo.poolSize || 10 },
|
||||
config: { autoIndex: false }
|
||||
})
|
||||
|
||||
const SamlLog = conn.model('SamlLog', SamlLogSchema)
|
||||
|
||||
mongoose.model('SamlLog', SamlLogSchema)
|
||||
exports.SamlLog = SamlLog
|
||||
exports.SamlLog = mongoose.model('SamlLog', SamlLogSchema)
|
||||
exports.SamlLogSchema = SamlLogSchema
|
||||
|
|
|
@ -1,8 +1,4 @@
|
|||
/* eslint-disable
|
||||
handle-callback-err
|
||||
*/
|
||||
const mongoose = require('mongoose')
|
||||
const Settings = require('settings-sharelatex')
|
||||
const mongoose = require('../infrastructure/Mongoose')
|
||||
const { TeamInviteSchema } = require('./TeamInvite')
|
||||
|
||||
const { Schema } = mongoose
|
||||
|
@ -43,19 +39,8 @@ SubscriptionSchema.statics.findAndModify = function(query, update, callback) {
|
|||
|
||||
// Subscriptions have no v1 data to fetch
|
||||
SubscriptionSchema.method('fetchV1Data', function(callback) {
|
||||
if (callback == null) {
|
||||
callback = function(error, subscription) {}
|
||||
}
|
||||
return callback(null, this)
|
||||
callback(null, this)
|
||||
})
|
||||
|
||||
const conn = mongoose.createConnection(Settings.mongo.url, {
|
||||
server: { poolSize: Settings.mongo.poolSize || 10 },
|
||||
config: { autoIndex: false }
|
||||
})
|
||||
|
||||
const Subscription = conn.model('Subscription', SubscriptionSchema)
|
||||
|
||||
mongoose.model('Subscription', SubscriptionSchema)
|
||||
exports.Subscription = Subscription
|
||||
exports.Subscription = mongoose.model('Subscription', SubscriptionSchema)
|
||||
exports.SubscriptionSchema = SubscriptionSchema
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
const mongoose = require('mongoose')
|
||||
const Settings = require('settings-sharelatex')
|
||||
const mongoose = require('../infrastructure/Mongoose')
|
||||
|
||||
const { Schema } = mongoose
|
||||
|
||||
|
@ -7,9 +6,4 @@ const SystemMessageSchema = new Schema({
|
|||
content: { type: String, default: '' }
|
||||
})
|
||||
|
||||
const conn = mongoose.createConnection(Settings.mongo.url, {
|
||||
server: { poolSize: Settings.mongo.poolSize || 10 },
|
||||
config: { autoIndex: false }
|
||||
})
|
||||
|
||||
exports.SystemMessage = conn.model('SystemMessage', SystemMessageSchema)
|
||||
exports.SystemMessage = mongoose.model('SystemMessage', SystemMessageSchema)
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
const mongoose = require('mongoose')
|
||||
const mongoose = require('../infrastructure/Mongoose')
|
||||
|
||||
const { Schema } = mongoose
|
||||
|
||||
|
@ -9,6 +9,5 @@ const TeamInviteSchema = new Schema({
|
|||
sentAt: { type: Date }
|
||||
})
|
||||
|
||||
mongoose.model('TeamInvite', TeamInviteSchema)
|
||||
exports.TeamInvite = mongoose.model('TeamInvite')
|
||||
exports.TeamInvite = mongoose.model('TeamInvite', TeamInviteSchema)
|
||||
exports.TeamInviteSchema = TeamInviteSchema
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
const Settings = require('settings-sharelatex')
|
||||
const mongoose = require('mongoose')
|
||||
const mongoose = require('../infrastructure/Mongoose')
|
||||
const uuid = require('uuid')
|
||||
const { Schema } = mongoose
|
||||
const { ObjectId } = Schema
|
||||
|
@ -119,13 +119,5 @@ const UserSchema = new Schema({
|
|||
migratedAt: { type: Date }
|
||||
})
|
||||
|
||||
const conn = mongoose.createConnection(Settings.mongo.url, {
|
||||
server: { poolSize: Settings.mongo.poolSize || 10 },
|
||||
config: { autoIndex: false }
|
||||
})
|
||||
|
||||
const User = conn.model('User', UserSchema)
|
||||
|
||||
mongoose.model('User', UserSchema)
|
||||
exports.User = User
|
||||
exports.User = mongoose.model('User', UserSchema)
|
||||
exports.UserSchema = UserSchema
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
const Settings = require('settings-sharelatex')
|
||||
const mongoose = require('mongoose')
|
||||
const mongoose = require('../infrastructure/Mongoose')
|
||||
const { Schema } = mongoose
|
||||
|
||||
const UserStubSchema = new Schema({
|
||||
|
@ -11,13 +10,5 @@ const UserStubSchema = new Schema({
|
|||
confirmed_at: Date
|
||||
})
|
||||
|
||||
const conn = mongoose.createConnection(Settings.mongo.url, {
|
||||
server: { poolSize: Settings.mongo.poolSize || 10 },
|
||||
config: { autoIndex: false }
|
||||
})
|
||||
|
||||
const UserStub = conn.model('UserStub', UserStubSchema)
|
||||
|
||||
mongoose.model('UserStub', UserStubSchema)
|
||||
exports.UserStub = UserStub
|
||||
exports.UserStub = mongoose.model('UserStub', UserStubSchema)
|
||||
exports.UserStubSchema = UserStubSchema
|
||||
|
|
|
@ -30,6 +30,7 @@ module.exports = settings =
|
|||
# ---------
|
||||
mongo:
|
||||
url : process.env['MONGO_CONNECTION_STRING'] || process.env['MONGO_URL'] || "mongodb://#{process.env['MONGO_HOST'] or '127.0.0.1'}/sharelatex"
|
||||
poolSize: parseInt(process.env['MONGO_POOL_SIZE'], 10) || 10
|
||||
|
||||
redis:
|
||||
web:
|
||||
|
|
|
@ -48,11 +48,9 @@ describe('SudoModeController', function() {
|
|||
'./SudoModeHandler': this.SudoModeHandler,
|
||||
'../Authentication/AuthenticationController': this
|
||||
.AuthenticationController,
|
||||
'../../infrastructure/Mongoose': {
|
||||
mongo: {
|
||||
ObjectId() {
|
||||
return 'some_object_id'
|
||||
}
|
||||
mongodb: {
|
||||
ObjectId() {
|
||||
return 'some_object_id'
|
||||
}
|
||||
},
|
||||
'../User/UserGetter': this.UserGetter,
|
||||
|
|
|
@ -17,7 +17,7 @@ const mongoose = require('mongoose')
|
|||
module.exports = (modelName, requires = {}) => {
|
||||
let model = {}
|
||||
|
||||
requires.mongoose = {
|
||||
requires['../infrastructure/Mongoose'] = {
|
||||
createConnection: () => {
|
||||
return {
|
||||
model: () => {}
|
||||
|
|
Loading…
Add table
Reference in a new issue