Update mongodb indexes
This commit is contained in:
parent
c0d14fe247
commit
8c0415c3f7
|
@ -9,6 +9,7 @@ import { ServerRenderer } from './utils/serverRender'
|
|||
import { Scanner } from './utils/scanner'
|
||||
import { FileStorage } from './utils/storage/file'
|
||||
import { MongoStorage } from './utils/storage/mongo'
|
||||
import { Api } from './utils/api'
|
||||
|
||||
const port = process.env.PORT || 3000
|
||||
const app = express()
|
||||
|
@ -53,6 +54,9 @@ if (config.storage === 'file') {
|
|||
storage = new MongoStorage(config)
|
||||
}
|
||||
|
||||
const postApi = new Api(storage)
|
||||
app.get('/api/v1/posts', postApi.getPosts.bind(postApi))
|
||||
|
||||
const scanner = new Scanner(config, storage)
|
||||
|
||||
const serverRenderer = new ServerRenderer(head, config, storage)
|
||||
|
|
|
@ -12,14 +12,20 @@ export class MongoStorage {
|
|||
link: String,
|
||||
body: String
|
||||
})
|
||||
PostSchema.index({ filename: 1 })
|
||||
PostSchema.index({
|
||||
body: 'text',
|
||||
title: 'text'
|
||||
})
|
||||
PostSchema.index({
|
||||
filename: 'hashed'
|
||||
})
|
||||
this.Post = mongoose.model('Post', PostSchema)
|
||||
|
||||
const OtherSchema = new Schema({
|
||||
filename: String,
|
||||
body: String
|
||||
})
|
||||
OtherSchema.index({ filename: 1 })
|
||||
OtherSchema.index({ filename: 'hashed' })
|
||||
this.Other = mongoose.model('Other', OtherSchema)
|
||||
|
||||
this.options = {
|
||||
|
@ -76,10 +82,7 @@ export class MongoStorage {
|
|||
this._getAllPosts()
|
||||
]).then((res) => {
|
||||
data.other.about = res[0].data
|
||||
data.posts = res[1].map((post) => {
|
||||
delete post.body
|
||||
return post
|
||||
})
|
||||
data.posts = res[1]
|
||||
return data
|
||||
})
|
||||
} else if (reqPath.startsWith('/post')) {
|
||||
|
@ -102,7 +105,7 @@ export class MongoStorage {
|
|||
|
||||
_getAllPosts () {
|
||||
return new Promise((resolve, reject) => {
|
||||
this.Post.find({}, (err, data) => {
|
||||
this.Post.find({}, { body: false }, (err, data) => {
|
||||
err ? reject(err) : resolve(data)
|
||||
})
|
||||
})
|
||||
|
|
Loading…
Reference in New Issue