Merge pull request #1557 from coralproject/indexes

Index Creation Patch
This commit is contained in:
Kim Gardner
2018-05-01 17:48:48 -04:00
committed by GitHub
3 changed files with 16 additions and 38 deletions
+1 -14
View File
@@ -1,5 +1,3 @@
const { CREATE_MONGO_INDEXES } = require('../../config');
const Action = require('./action');
const Asset = require('./asset');
const Comment = require('./comment');
@@ -7,15 +5,4 @@ const Migration = require('./migration');
const Setting = require('./setting');
const User = require('./user');
const schema = { Action, Asset, Comment, Migration, Setting, User };
// Provide the schema to each of the plugins so that they can add in indexes if
// it is enabled.
if (CREATE_MONGO_INDEXES) {
const plugins = require('../../services/plugins');
plugins.get('server', 'indexes').map(({ indexes }) => {
indexes(schema);
});
}
module.exports = schema;
module.exports = { Action, Asset, Comment, Migration, Setting, User };
+14 -24
View File
@@ -2,23 +2,24 @@ const { SEARCH_OTHER_USERS } = require('../../../perms/constants');
const { ErrNotFound, ErrAlreadyExists } = require('../../../errors');
const pluralize = require('pluralize');
const sc = require('snake-case');
// const { CREATE_MONGO_INDEXES } = require('../../../config');
const { CREATE_MONGO_INDEXES } = require('../../../config');
const Comment = require('models/comment');
function getReactionConfig(reaction) {
reaction = reaction.toLowerCase();
// if (CREATE_MONGO_INDEXES) {
// // Create the index on the comment model based on the reaction config.
// CommentModel.collection.createIndex(
// {
// created_at: 1,
// [`action_counts.${sc(reaction)}`]: 1,
// },
// {
// background: true,
// }
// );
// }
if (CREATE_MONGO_INDEXES) {
// Create the index on the comment model based on the reaction config.
Comment.collection.createIndex(
{
created_at: 1,
[`action_counts.${sc(reaction)}`]: 1,
},
{
background: true,
}
);
}
const reactionPlural = pluralize(reaction);
const Reaction = reaction.charAt(0).toUpperCase() + reaction.slice(1);
@@ -127,17 +128,6 @@ function getReactionConfig(reaction) {
return {
typeDefs,
indexes: ({ Comment }) => {
Comment.index(
{
created_at: 1,
[`action_counts.${sc(reaction)}`]: 1,
},
{
background: true,
}
);
},
context: {
Sort: () => ({
Comments: {
+1
View File
@@ -66,6 +66,7 @@ if (CREATE_MONGO_INDEXES) {
require('../models/action');
require('../models/asset');
require('../models/comment');
require('../models/migration');
require('../models/setting');
require('../models/user');
require('./migration');