Quellcode durchsuchen

add index to in-app-notification

Yuki Takei vor 1 Jahr
Ursprung
Commit
6de9a2a802
1 geänderte Dateien mit 6 neuen und 4 gelöschten Zeilen
  1. 6 4
      apps/app/src/server/models/in-app-notification.ts

+ 6 - 4
apps/app/src/server/models/in-app-notification.ts

@@ -1,6 +1,5 @@
-import {
-  Types, Document, Schema, Model,
-} from 'mongoose';
+import type { Types, Document, Model } from 'mongoose';
+import { Schema } from 'mongoose';
 import mongoosePaginate from 'mongoose-paginate-v2';
 import mongoosePaginate from 'mongoose-paginate-v2';
 
 
 import { AllSupportedTargetModels, AllSupportedActions } from '~/interfaces/activity';
 import { AllSupportedTargetModels, AllSupportedActions } from '~/interfaces/activity';
@@ -8,7 +7,7 @@ import { InAppNotificationStatuses } from '~/interfaces/in-app-notification';
 
 
 import { getOrCreateModel } from '../util/mongoose-utils';
 import { getOrCreateModel } from '../util/mongoose-utils';
 
 
-import { ActivityDocument } from './activity';
+import type { ActivityDocument } from './activity';
 
 
 
 
 const { STATUS_UNREAD, STATUS_UNOPENED, STATUS_OPENED } = InAppNotificationStatuses;
 const { STATUS_UNREAD, STATUS_UNOPENED, STATUS_OPENED } = InAppNotificationStatuses;
@@ -79,6 +78,9 @@ const inAppNotificationSchema = new Schema<InAppNotificationDocument, InAppNotif
 }, {
 }, {
   timestamps: { createdAt: true, updatedAt: false },
   timestamps: { createdAt: true, updatedAt: false },
 });
 });
+// indexes
+inAppNotificationSchema.index({ createdAt: 1 });
+// apply plugins
 inAppNotificationSchema.plugin(mongoosePaginate);
 inAppNotificationSchema.plugin(mongoosePaginate);
 
 
 const transform = (doc, ret) => {
 const transform = (doc, ret) => {