Skip to content

Commit

Permalink
perf: 增加索引
Browse files Browse the repository at this point in the history
  • Loading branch information
Mereithhh committed Jan 29, 2023
1 parent 5fe6898 commit a4fcaca
Show file tree
Hide file tree
Showing 10 changed files with 22 additions and 10 deletions.
4 changes: 3 additions & 1 deletion packages/server/src/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,9 @@ import { Category, CategorySchema } from './scheme/category.schema';

@Module({
imports: [
MongooseModule.forRoot(config.mongoUrl),
MongooseModule.forRoot(config.mongoUrl, {
autoIndex: true,
}),
MongooseModule.forFeature([
{ name: Article.name, schema: ArticleSchema },
{ name: Draft.name, schema: DraftSchema },
Expand Down
6 changes: 4 additions & 2 deletions packages/server/src/scheme/article.schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export class Article extends Document {
@Prop({ index: true, unique: true })
id: number;

@Prop()
@Prop({ index: true })
title: string;

@Prop({ default: '' })
Expand All @@ -26,7 +26,7 @@ export class Article extends Document {
@Prop({ default: false, index: true })
hidden: boolean;

@Prop()
@Prop({ index: true })
author: string;

@Prop({ default: false, index: true })
Expand All @@ -51,13 +51,15 @@ export class Article extends Document {
lastVisitedTime: Date;

@Prop({
index: true,
default: () => {
return new Date();
},
})
createdAt: Date;

@Prop({
index: true,
default: () => {
return new Date();
},
Expand Down
6 changes: 3 additions & 3 deletions packages/server/src/scheme/category.schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ export class Category extends Document {
@Prop({ index: true, unique: true })
id: number;

@Prop({ unique: true })
@Prop({ unique: true, index: true })
name: string;

@Prop({ default: 'category' })
@Prop({ default: 'category', index: true })
type: CategoryType;

@Prop({ default: false })
@Prop({ default: false, index: true })
private: boolean;

@Prop()
Expand Down
2 changes: 2 additions & 0 deletions packages/server/src/scheme/customPage.schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,15 @@ export class CustomPage extends Document {
html: string;

@Prop({
index: true,
default: () => {
return new Date();
},
})
createdAt: Date;

@Prop({
index: true,
default: () => {
return new Date();
},
Expand Down
6 changes: 4 additions & 2 deletions packages/server/src/scheme/draft.schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export class Draft extends Document {
@Prop({ index: true, unique: true })
id: number;

@Prop()
@Prop({ index: true })
title: string;

@Prop({ default: '' })
Expand All @@ -17,7 +17,7 @@ export class Draft extends Document {
@Prop({ default: [], index: true })
tags: string[];

@Prop()
@Prop({ index: true })
author: string;

@Prop({ index: true })
Expand All @@ -27,13 +27,15 @@ export class Draft extends Document {
deleted: boolean;

@Prop({
index: true,
default: () => {
return new Date();
},
})
createdAt: Date;

@Prop({
index: true,
default: () => {
return new Date();
},
Expand Down
1 change: 1 addition & 0 deletions packages/server/src/scheme/static.schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ export class Static extends Document {
sign: string;

@Prop({
index: true,
default: () => {
return new Date();
},
Expand Down
1 change: 1 addition & 0 deletions packages/server/src/scheme/token.schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export class Token extends Document {
expiresIn: number;

@Prop({
index: true,
default: () => {
return new Date();
},
Expand Down
2 changes: 1 addition & 1 deletion packages/server/src/scheme/user.schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export class User extends Document {
@Prop({ index: true, unique: true })
id: number;

@Prop()
@Prop({ index: true })
name: string;

@Prop()
Expand Down
1 change: 1 addition & 0 deletions packages/server/src/scheme/viewer.schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export class Viewer extends Document {
date: string;

@Prop({
index: true,
default: () => {
return new Date();
},
Expand Down
3 changes: 2 additions & 1 deletion packages/server/src/scheme/visit.schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,11 @@ export class Visit extends Document {
@Prop({ index: true })
pathname: string;

@Prop()
@Prop({ index: true })
lastVisitedTime: Date;

@Prop({
index: true,
default: () => {
return new Date();
},
Expand Down

0 comments on commit a4fcaca

Please sign in to comment.