diff --git a/server/achievements/Achievement.coffee b/server/achievements/Achievement.coffee index 33675e7ee..d3046546e 100644 --- a/server/achievements/Achievement.coffee +++ b/server/achievements/Achievement.coffee @@ -15,6 +15,22 @@ AchievementSchema = new mongoose.Schema({ userField: String }, {strict: false}) +AchievementSchema.index( + { + _fts: 'text' + _ftsx: 1 + }, + { + name: 'search index' + sparse: true + weights: {name: 1} + default_language: 'english' + 'language_override': 'language' + 'textIndexVersion': 2 + }) +AchievementSchema.index({i18nCoverage: 1}, {name: 'translation coverage index', sparse: true}) +AchievementSchema.index({slug: 1}, {name: 'slug index', sparse: true, unique: true}) + AchievementSchema.methods.objectifyQuery = -> try @set('query', JSON.parse(@get('query'))) if typeof @get('query') == 'string' diff --git a/server/analytics/AnalyticsLogEvent.coffee b/server/analytics/AnalyticsLogEvent.coffee index 18a146346..be9a5b461 100644 --- a/server/analytics/AnalyticsLogEvent.coffee +++ b/server/analytics/AnalyticsLogEvent.coffee @@ -11,6 +11,7 @@ AnalyticsLogEventSchema = new mongoose.Schema({ event: String properties: mongoose.Schema.Types.Mixed }, {strict: false}) + AnalyticsLogEventSchema.index({event: 1, _id: 1}) module.exports = AnalyticsLogEvent = mongoose.model('analytics.log.event', AnalyticsLogEventSchema) diff --git a/server/analytics/AnalyticsUsersActive.coffee b/server/analytics/AnalyticsUsersActive.coffee index 95614335d..8182a596d 100644 --- a/server/analytics/AnalyticsUsersActive.coffee +++ b/server/analytics/AnalyticsUsersActive.coffee @@ -7,4 +7,7 @@ AnalyticsUsersActiveSchema = new mongoose.Schema({ 'default': Date.now }, {strict: false}) +AnalyticsUsersActiveSchema.index({created: 1}) +AnalyticsUsersActiveSchema.index({creator: 1}) + module.exports = AnalyticsUsersActive = mongoose.model('analytics.users.active', AnalyticsUsersActiveSchema) diff --git a/server/articles/Article.coffee b/server/articles/Article.coffee index 1645b15b6..df242e771 100644 --- a/server/articles/Article.coffee +++ b/server/articles/Article.coffee @@ -3,6 +3,32 @@ plugins = require '../plugins/plugins' ArticleSchema = new mongoose.Schema(body: String, {strict: false}) +ArticleSchema.index( + { + index: 1 + _fts: 'text' + _ftsx: 1 + }, + { + name: 'search index' + sparse: true + weights: {body: 1, name: 1} + default_language: 'english' + 'language_override': 'searchLanguage' + 'textIndexVersion': 2 + }) +ArticleSchema.index( + { + original: 1 + 'version.major': -1 + 'version.minor': -1 + }, + { + name: 'version index' + unique: true + }) +ArticleSchema.index({slug: 1}, {name: 'slug index', sparse: true, unique: true}) + ArticleSchema.plugin(plugins.NamedPlugin) ArticleSchema.plugin(plugins.VersionedPlugin) ArticleSchema.plugin(plugins.SearchablePlugin, {searchable: ['body', 'name']}) diff --git a/server/campaigns/Campaign.coffee b/server/campaigns/Campaign.coffee index b0fad1371..b32d72cf1 100644 --- a/server/campaigns/Campaign.coffee +++ b/server/campaigns/Campaign.coffee @@ -3,6 +3,9 @@ plugins = require '../plugins/plugins' CampaignSchema = new mongoose.Schema(body: String, {strict: false}) +CampaignSchema.index({i18nCoverage: 1}, {name: 'translation coverage index', sparse: true}) +CampaignSchema.index({slug: 1}, {name: 'slug index', sparse: true, unique: true}) + CampaignSchema.plugin(plugins.NamedPlugin) CampaignSchema.plugin(plugins.TranslationCoveragePlugin) diff --git a/server/levels/Level.coffee b/server/levels/Level.coffee index 95d2bc4b7..b27264615 100644 --- a/server/levels/Level.coffee +++ b/server/levels/Level.coffee @@ -6,6 +6,32 @@ LevelSchema = new mongoose.Schema({ description: String }, {strict: false}) +LevelSchema.index( + { + index: 1 + _fts: 'text' + _ftsx: 1 + }, + { + name: 'search index' + sparse: true + weights: {description: 1, name: 1} + default_language: 'english' + 'language_override': 'searchLanguage' + 'textIndexVersion': 2 + }) +LevelSchema.index( + { + original: 1 + 'version.major': -1 + 'version.minor': -1 + }, + { + name: 'version index' + unique: true + }) +LevelSchema.index({slug: 1}, {name: 'slug index', sparse: true, unique: true}) + LevelSchema.plugin(plugins.NamedPlugin) LevelSchema.plugin(plugins.PermissionsPlugin) LevelSchema.plugin(plugins.VersionedPlugin) diff --git a/server/levels/components/LevelComponent.coffee b/server/levels/components/LevelComponent.coffee index a714129c0..46f36822f 100644 --- a/server/levels/components/LevelComponent.coffee +++ b/server/levels/components/LevelComponent.coffee @@ -7,6 +7,32 @@ LevelComponentSchema = new mongoose.Schema { system: String }, {strict: false} +LevelComponentSchema.index( + { + index: 1 + _fts: 'text' + _ftsx: 1 + }, + { + name: 'search index' + sparse: true + weights: {description: 1, name: 1, searchStrings: 1} + default_language: 'english' + 'language_override': 'searchLanguage' + 'textIndexVersion': 2 + }) +LevelComponentSchema.index( + { + original: 1 + 'version.major': -1 + 'version.minor': -1 + }, + { + name: 'version index' + unique: true + }) +LevelComponentSchema.index({slug: 1}, {name: 'slug index', sparse: true, unique: true}) + LevelComponentSchema.plugin plugins.NamedPlugin LevelComponentSchema.plugin plugins.PermissionsPlugin LevelComponentSchema.plugin plugins.VersionedPlugin diff --git a/server/levels/feedbacks/LevelFeedback.coffee b/server/levels/feedbacks/LevelFeedback.coffee index 523bf9120..8d004c48b 100644 --- a/server/levels/feedbacks/LevelFeedback.coffee +++ b/server/levels/feedbacks/LevelFeedback.coffee @@ -10,4 +10,7 @@ LevelFeedbackSchema = new mongoose.Schema({ 'default': Date.now }, {strict: false}) +LevelFeedbackSchema.index({created: 1}) +LevelFeedbackSchema.index({creator: 1}) + module.exports = LevelFeedback = mongoose.model('level.feedback', LevelFeedbackSchema) diff --git a/server/levels/sessions/LevelSession.coffee b/server/levels/sessions/LevelSession.coffee index 7832875c0..8285e6790 100644 --- a/server/levels/sessions/LevelSession.coffee +++ b/server/levels/sessions/LevelSession.coffee @@ -11,6 +11,20 @@ LevelSessionSchema = new mongoose.Schema({ type: Date 'default': Date.now }, {strict: false}) + +LevelSessionSchema.index({creator: 1}) +LevelSessionSchema.index({level: 1}) +LevelSessionSchema.index({levelID: 1}) +LevelSessionSchema.index({'level.majorVersion': 1}) +LevelSessionSchema.index({'level.original': 1}, {name: 'Level Original'}) +LevelSessionSchema.index({'level.original': 1, 'level.majorVersion': 1, 'creator': 1, 'team': 1}) +LevelSessionSchema.index({playtime: 1}, {name: 'Playtime'}) +LevelSessionSchema.index({submitDate: 1}) +LevelSessionSchema.index({submitted: 1}, {sparse: true}) +LevelSessionSchema.index({team: 1}, {sparse: true}) +LevelSessionSchema.index({totalScore: 1}, {sparse: true}) +LevelSessionSchema.index({user: 1, changed: -1}, {name: 'last played index', sparse: true}) + LevelSessionSchema.plugin(plugins.PermissionsPlugin) LevelSessionSchema.plugin(AchievablePlugin) diff --git a/server/levels/systems/LevelSystem.coffee b/server/levels/systems/LevelSystem.coffee index 87c4a2bab..0b0279baa 100644 --- a/server/levels/systems/LevelSystem.coffee +++ b/server/levels/systems/LevelSystem.coffee @@ -6,6 +6,32 @@ LevelSystemSchema = new mongoose.Schema { description: String }, {strict: false} +LevelSystemSchema.index( + { + index: 1 + _fts: 'text' + _ftsx: 1 + }, + { + name: 'search index' + sparse: true + weights: {description: 1, name: 1, name: 1} + default_language: 'english' + 'language_override': 'searchLanguage' + 'textIndexVersion': 2 + }) +LevelSystemSchema.index( + { + original: 1 + 'version.major': -1 + 'version.minor': -1 + }, + { + name: 'version index' + unique: true + }) +LevelSystemSchema.index({slug: 1}, {name: 'slug index', sparse: true, unique: true}) + LevelSystemSchema.plugin(plugins.NamedPlugin) LevelSystemSchema.plugin(plugins.PermissionsPlugin) LevelSystemSchema.plugin(plugins.VersionedPlugin) diff --git a/server/levels/thangs/ThangType.coffee b/server/levels/thangs/ThangType.coffee index 02259caa3..605cb97a9 100644 --- a/server/levels/thangs/ThangType.coffee +++ b/server/levels/thangs/ThangType.coffee @@ -5,6 +5,32 @@ ThangTypeSchema = new mongoose.Schema({ body: String, }, {strict: false}) +ThangTypeSchema.index( + { + index: 1 + _fts: 'text' + _ftsx: 1 + }, + { + name: 'search index' + sparse: true + weights: {name: 1} + default_language: 'english' + 'language_override': 'searchLanguage' + 'textIndexVersion': 2 + }) +ThangTypeSchema.index( + { + original: 1 + 'version.major': -1 + 'version.minor': -1 + }, + { + name: 'version index' + unique: true + }) +ThangTypeSchema.index({slug: 1}, {name: 'slug index', sparse: true, unique: true}) + ThangTypeSchema.plugin plugins.NamedPlugin ThangTypeSchema.plugin plugins.VersionedPlugin ThangTypeSchema.plugin plugins.SearchablePlugin, {searchable: ['name']} diff --git a/server/mail/sent/MailSent.coffee b/server/mail/sent/MailSent.coffee index f8479033a..f87bc6743 100644 --- a/server/mail/sent/MailSent.coffee +++ b/server/mail/sent/MailSent.coffee @@ -8,4 +8,6 @@ MailSent = new mongoose.Schema({ 'default': Date.now }, {strict: false}) +MailSent.index({user: 1}, {name: 'User'}) + module.exports = MailSent = mongoose.model('mail.sent', MailSent) diff --git a/server/queues/task/ScoringTask.coffee b/server/queues/task/ScoringTask.coffee index b6dcf27d9..e24a56130 100644 --- a/server/queues/task/ScoringTask.coffee +++ b/server/queues/task/ScoringTask.coffee @@ -9,4 +9,6 @@ ScoringTaskSchema = new mongoose.Schema( sessions: {type: Array, default: []} ) +ScoringTaskSchema.index({createdAt: 1}, {expireAfterSeconds: 3600}) + module.exports = mongoose.model('scoringTask', ScoringTaskSchema) diff --git a/server/user_code_problems/UserCodeProblem.coffee b/server/user_code_problems/UserCodeProblem.coffee index f03168b34..809d5ee4d 100644 --- a/server/user_code_problems/UserCodeProblem.coffee +++ b/server/user_code_problems/UserCodeProblem.coffee @@ -7,4 +7,6 @@ UserCodeProblemSchema = new mongoose.Schema({ 'default': Date.now }, {strict: false}) +# TODO: add index + module.exports = UserCodeProblem = mongoose.model('user.code.problem', UserCodeProblemSchema) diff --git a/server/users/User.coffee b/server/users/User.coffee index 3253344d8..61596c6f5 100644 --- a/server/users/User.coffee +++ b/server/users/User.coffee @@ -19,6 +19,17 @@ UserSchema = new mongoose.Schema({ 'default': Date.now }, {strict: false}) +UserSchema.index({'dateCreated': 1}) +UserSchema.index({'emailLower': 1}, {unique: true, sparse: true, name: 'emailLower_1'}) +UserSchema.index({'facebookID': 1}, {sparse: true}) +UserSchema.index({'gplusID': 1}, {sparse: true}) +UserSchema.index({'iosIdentifierForVendor': 1}, {name: 'iOS identifier for vendor', sparse: true, unique: true}) +UserSchema.index({'mailChimp.leid': 1}, {sparse: true}) +UserSchema.index({'nameLower': 1}, {sparse: true, name: 'nameLower_1'}) +UserSchema.index({'simulatedBy': 1}) +UserSchema.index({'slug': 1}, {name: 'slug index', sparse: true, unique: true}) +UserSchema.index({'stripe.subscriptionID': 1}, {unique: true, sparse: true}) + UserSchema.post('init', -> @set('anonymous', false) if @get('email') ) @@ -266,9 +277,6 @@ UserSchema.statics.editableProperties = [ ] UserSchema.plugin plugins.NamedPlugin -UserSchema.index({'stripe.subscriptionID':1}, {unique: true, sparse: true}) -UserSchema.index({'emailLower':1}, {unique: true, sparse: true, name: 'emailLower_1'}) -UserSchema.index({'nameLower':1}, {unique: true, sparse: true, name: 'nameLower_1'}) module.exports = User = mongoose.model('User', UserSchema) diff --git a/server/users/remarks/UserRemark.coffee b/server/users/remarks/UserRemark.coffee index 445340c0b..15eb63a2b 100644 --- a/server/users/remarks/UserRemark.coffee +++ b/server/users/remarks/UserRemark.coffee @@ -8,4 +8,6 @@ UserRemarkSchema = new mongoose.Schema({ 'default': Date.now }, {strict: false}) +UserRemarkSchema.index({user: 1}, {name: 'User'}) + module.exports = UserRemark = mongoose.model('user.remark', UserRemarkSchema)