mirror of
https://github.com/wassname/talk.git
synced 2026-08-01 13:00:55 +08:00
fixes for index creation
This commit is contained in:
@@ -0,0 +1,34 @@
|
||||
const { reduce } = require('lodash');
|
||||
const { CREATE_MONGO_INDEXES } = require('../config');
|
||||
|
||||
const Action = require('./action');
|
||||
const Asset = require('./asset');
|
||||
const Comment = require('./comment');
|
||||
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');
|
||||
|
||||
// Remap all of the models to their driver reference via the `collection`
|
||||
// field.
|
||||
const collections = reduce(
|
||||
schema,
|
||||
(collections, model, modelName) => {
|
||||
collections[modelName] = model.collection;
|
||||
return collections;
|
||||
},
|
||||
{}
|
||||
);
|
||||
|
||||
// Defer the instantiation of the index caller functions when we're creating
|
||||
// indexes.
|
||||
plugins.defer('server', 'indexes', ({ indexes }) => {
|
||||
indexes(collections);
|
||||
});
|
||||
}
|
||||
+1
-14
@@ -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 };
|
||||
|
||||
@@ -128,7 +128,7 @@ function getReactionConfig(reaction) {
|
||||
return {
|
||||
typeDefs,
|
||||
indexes: ({ Comment }) => {
|
||||
Comment.index(
|
||||
Comment.ensureIndex(
|
||||
{
|
||||
created_at: 1,
|
||||
[`action_counts.${sc(reaction)}`]: 1,
|
||||
|
||||
@@ -63,10 +63,6 @@ module.exports = mongoose;
|
||||
// here. No point also in importing this if we're not actually doing any
|
||||
// indexing now.
|
||||
if (CREATE_MONGO_INDEXES) {
|
||||
require('../models/action');
|
||||
require('../models/asset');
|
||||
require('../models/comment');
|
||||
require('../models/setting');
|
||||
require('../models/user');
|
||||
require('../models');
|
||||
require('./migration');
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user