Merge pull request #142 from sharelatex/sk-fix-token-indexes

use correct partial indexes on project token fields
This commit is contained in:
Shane Kilkelly 2017-11-23 10:30:31 +00:00 committed by GitHub
commit 10fc89c8cf
7 changed files with 45 additions and 15 deletions

View file

@ -2,7 +2,10 @@ mongoose = require('mongoose')
Settings = require 'settings-sharelatex' Settings = require 'settings-sharelatex'
logger = require('logger-sharelatex') logger = require('logger-sharelatex')
mongoose.connect(Settings.mongo.url, server: poolSize: 10) mongoose.connect(Settings.mongo.url, {
server: {poolSize: 10},
config: {autoIndex: false}
})
mongoose.connection.on 'connected', () -> mongoose.connection.on 'connected', () ->
logger.log {url:Settings.mongo.url}, 'mongoose default connection open' logger.log {url:Settings.mongo.url}, 'mongoose default connection open'

View file

@ -33,8 +33,20 @@ ProjectSchema = new Schema
imageName : { type: String } imageName : { type: String }
track_changes : { type: Object } track_changes : { type: Object }
tokens : tokens :
readOnly : { type: String, index: {unique: true} } readOnly : {
readAndWrite : { type: String, index: {unique: true} } type: String,
index: {
unique: true,
partialFilterExpression: {'tokens.readOnly': {$exists: true}}
}
}
readAndWrite : {
type: String,
index: {
unique: true,
partialFilterExpression: {'tokens.readAndWrite': {$exists: true}}
}
}
tokenAccessReadOnly_refs : [ type:ObjectId, ref:'User' ] tokenAccessReadOnly_refs : [ type:ObjectId, ref:'User' ]
tokenAccessReadAndWrite_refs : [ type:ObjectId, ref:'User' ] tokenAccessReadAndWrite_refs : [ type:ObjectId, ref:'User' ]
overleaf : overleaf :
@ -61,12 +73,14 @@ applyToAllFilesRecursivly = ProjectSchema.statics.applyToAllFilesRecursivly = (f
_.each folder.folders, (folder)-> _.each folder.folders, (folder)->
applyToAllFilesRecursivly(folder, fun) applyToAllFilesRecursivly(folder, fun)
ProjectSchema.methods.getSafeProjectName = -> ProjectSchema.methods.getSafeProjectName = ->
safeProjectName = this.name.replace(new RegExp("\\W", "g"), '_') safeProjectName = this.name.replace(new RegExp("\\W", "g"), '_')
return sanitize.escape(safeProjectName) return sanitize.escape(safeProjectName)
conn = mongoose.createConnection(Settings.mongo.url, server: poolSize: Settings.mongo.poolSize || 10) conn = mongoose.createConnection(Settings.mongo.url, {
server: {poolSize: Settings.mongo.poolSize || 10},
config: {autoIndex: false}
})
Project = conn.model('Project', ProjectSchema) Project = conn.model('Project', ProjectSchema)

View file

@ -30,9 +30,10 @@ ProjectInviteSchema = new Schema(
} }
) )
conn = mongoose.createConnection(Settings.mongo.url, {
conn = mongoose.createConnection(Settings.mongo.url, server: poolSize: Settings.mongo.poolSize || 10) server: {poolSize: Settings.mongo.poolSize || 10},
config: {autoIndex: false}
})
ProjectInvite = conn.model('ProjectInvite', ProjectInviteSchema) ProjectInvite = conn.model('ProjectInvite', ProjectInviteSchema)

View file

@ -25,11 +25,13 @@ SubscriptionSchema.statics.findAndModify = (query, update, callback)->
this.update query, update, -> this.update query, update, ->
self.findOne query, callback self.findOne query, callback
conn = mongoose.createConnection(Settings.mongo.url, {
conn = mongoose.createConnection(Settings.mongo.url, server: poolSize: Settings.mongo.poolSize || 10) server: {poolSize: Settings.mongo.poolSize || 10},
config: {autoIndex: false}
})
Subscription = conn.model('Subscription', SubscriptionSchema) Subscription = conn.model('Subscription', SubscriptionSchema)
mongoose.model 'Subscription', SubscriptionSchema mongoose.model 'Subscription', SubscriptionSchema
exports.Subscription = Subscription exports.Subscription = Subscription
exports.SubscriptionSchema = SubscriptionSchema exports.SubscriptionSchema = SubscriptionSchema

View file

@ -6,7 +6,11 @@ ObjectId = Schema.ObjectId
SystemMessageSchema = new Schema SystemMessageSchema = new Schema
content : type: String, default:'' content : type: String, default:''
conn = mongoose.createConnection(Settings.mongo.url, server: poolSize: Settings.mongo.poolSize || 10) conn = mongoose.createConnection(Settings.mongo.url, {
server: {poolSize: Settings.mongo.poolSize || 10},
config: {autoIndex: false}
})
exports.SystemMessage = conn.model('SystemMessage', SystemMessageSchema) exports.SystemMessage = conn.model('SystemMessage', SystemMessageSchema)

View file

@ -64,7 +64,10 @@ UserSchema = new Schema
accessToken: { type: String } accessToken: { type: String }
refreshToken: { type: String } refreshToken: { type: String }
conn = mongoose.createConnection(Settings.mongo.url, server: poolSize: 10) conn = mongoose.createConnection(Settings.mongo.url, {
server: {poolSize: Settings.mongo.poolSize || 10},
config: {autoIndex: false}
})
User = conn.model('User', UserSchema) User = conn.model('User', UserSchema)

View file

@ -9,7 +9,10 @@ UserStubSchema = new Schema
last_name : { type : String, default : '' } last_name : { type : String, default : '' }
overleaf : { id: { type: Number } } overleaf : { id: { type: Number } }
conn = mongoose.createConnection(Settings.mongo.url, server: poolSize: 10) conn = mongoose.createConnection(Settings.mongo.url, {
server: {poolSize: Settings.mongo.poolSize || 10},
config: {autoIndex: false}
})
UserStub = conn.model('UserStub', UserStubSchema) UserStub = conn.model('UserStub', UserStubSchema)