adjusted index creation and managemen

This commit is contained in:
Wyatt Johnson
2018-04-12 09:37:17 -06:00
parent 68473e5a29
commit 10d11c1615
17 changed files with 1027 additions and 926 deletions
+15 -16
View File
@@ -2,24 +2,23 @@ const { SEARCH_OTHER_USERS } = require('../../../perms/constants');
const { ErrNotFound, ErrAlreadyExists } = require('../../../errors');
const pluralize = require('pluralize');
const sc = require('snake-case');
const CommentModel = require('../../../models/comment');
const { CREATE_MONGO_INDEXES } = require('../../../config');
// const { CREATE_MONGO_INDEXES } = require('../../../config');
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.
// CommentModel.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);
@@ -128,8 +127,8 @@ function getReactionConfig(reaction) {
return {
typeDefs,
schemas: ({ CommentSchema }) => {
CommentSchema.index(
indexes: ({ Comment }) => {
Comment.index(
{
created_at: 1,
[`action_counts.${sc(reaction)}`]: 1,