mirror of
https://github.com/naturalcrit/homebrewery.git
synced 2025-12-24 20:42:43 +00:00
Merge pull request #4436 from G-Ambatte/addMongoIndexes
Add indexes to Mongo schema
This commit is contained in:
@@ -75,8 +75,9 @@ it using the two commands:
|
||||
1. `npm install`
|
||||
1. `npm start`
|
||||
|
||||
You should now be able to go to [http://localhost:8000](http://localhost:8000)
|
||||
in your browser and use The Homebrewery offline.
|
||||
When the Homebrewery server is started for the first time, it will modify the database to create the indexes required for better Homebrewery performance. This may take a few moments to complete for each index, dependent on how much content is in your local database - a brand new, empty database should be done in seconds.
|
||||
|
||||
On completion, you should be able to go to [http://localhost:8000](http://localhost:8000) in your browser and use The Homebrewery offline.
|
||||
|
||||
If you had any issue at all, here are some links that may be useful:
|
||||
- [Course](https://learn.mongodb.com/courses/m103-basic-cluster-administration) on cluster administration, useful for beginners
|
||||
@@ -145,3 +146,4 @@ your contribution to the project, please join our [gitter chat][gitter-url].
|
||||
[github-pr-docs-url]: https://docs.github.com/en/free-pro-team@latest/github/collaborating-with-issues-and-pull-requests/creating-a-pull-request
|
||||
[gitter-url]: https://gitter.im/naturalcrit/Lobby
|
||||
|
||||
|
||||
|
||||
@@ -27,7 +27,10 @@ const disconnect = async ()=>{
|
||||
};
|
||||
|
||||
const connect = async (config)=>{
|
||||
return await Mongoose.connect(getMongoDBURL(config), { retryWrites: false })
|
||||
return await Mongoose.connect(getMongoDBURL(config), {
|
||||
retryWrites : false,
|
||||
autoIndex : (config.get('local_environments').includes(config.get('node_env')))
|
||||
})
|
||||
.catch((error)=>handleConnectionError(error));
|
||||
};
|
||||
|
||||
|
||||
@@ -7,29 +7,29 @@ import zlib from 'zlib';
|
||||
const HomebrewSchema = mongoose.Schema({
|
||||
shareId : { type: String, default: ()=>{return nanoid(12);}, index: { unique: true } },
|
||||
editId : { type: String, default: ()=>{return nanoid(12);}, index: { unique: true } },
|
||||
googleId : { type: String },
|
||||
title : { type: String, default: '' },
|
||||
googleId : { type: String, index: true },
|
||||
title : { type: String, default: '', index: true },
|
||||
text : { type: String, default: '' },
|
||||
textBin : { type: Buffer },
|
||||
pageCount : { type: Number, default: 1 },
|
||||
pageCount : { type: Number, default: 1, index: true },
|
||||
|
||||
description : { type: String, default: '' },
|
||||
tags : [String],
|
||||
tags : { type: [String], index: true },
|
||||
systems : [String],
|
||||
lang : { type: String, default: 'en' },
|
||||
renderer : { type: String, default: '' },
|
||||
authors : [String],
|
||||
lang : { type: String, default: 'en', index: true },
|
||||
renderer : { type: String, default: '', index: true },
|
||||
authors : { type: [String], index: true },
|
||||
invitedAuthors : [String],
|
||||
published : { type: Boolean, default: false },
|
||||
thumbnail : { type: String, default: '' },
|
||||
published : { type: Boolean, default: false, index: true },
|
||||
thumbnail : { type: String, default: '', index: true },
|
||||
|
||||
createdAt : { type: Date, default: Date.now },
|
||||
updatedAt : { type: Date, default: Date.now },
|
||||
lastViewed : { type: Date, default: Date.now },
|
||||
createdAt : { type: Date, default: Date.now, index: true },
|
||||
updatedAt : { type: Date, default: Date.now, index: true },
|
||||
lastViewed : { type: Date, default: Date.now, index: true },
|
||||
views : { type: Number, default: 0 },
|
||||
version : { type: Number, default: 1 },
|
||||
version : { type: Number, default: 1, index: true },
|
||||
|
||||
lock : { type: Object }
|
||||
lock : { type: Object, index: true }
|
||||
}, { versionKey: false });
|
||||
|
||||
HomebrewSchema.statics.increaseView = async function(query) {
|
||||
@@ -43,6 +43,8 @@ HomebrewSchema.statics.increaseView = async function(query) {
|
||||
return brew;
|
||||
};
|
||||
|
||||
// STATIC FUNCTIONS
|
||||
|
||||
HomebrewSchema.statics.get = async function(query, fields=null){
|
||||
const brew = await Homebrew.findOne(query, fields).orFail()
|
||||
.catch((error)=>{throw 'Can not find brew';});
|
||||
@@ -63,6 +65,15 @@ HomebrewSchema.statics.getByUser = async function(username, allowAccess=false, f
|
||||
return brews;
|
||||
};
|
||||
|
||||
// INDEXES
|
||||
|
||||
HomebrewSchema.index({ updatedAt: -1, lastViewed: -1 });
|
||||
HomebrewSchema.index({ published: 1, title: 'text' });
|
||||
|
||||
HomebrewSchema.index({ lock: 1, sparse: true });
|
||||
HomebrewSchema.path('lock.reviewRequested').index({ sparse: true });
|
||||
|
||||
|
||||
const Homebrew = mongoose.model('Homebrew', HomebrewSchema);
|
||||
|
||||
export {
|
||||
|
||||
Reference in New Issue
Block a user