|
|
@@ -30,7 +30,7 @@ export interface ActivityModel extends Model<ActivityDocument> {
|
|
|
}
|
|
|
|
|
|
const snapshotSchema = new Schema<ISnapshot>({
|
|
|
- username: { type: String },
|
|
|
+ username: { type: String, index: true },
|
|
|
});
|
|
|
|
|
|
// TODO: add revision id
|
|
|
@@ -116,9 +116,10 @@ activitySchema.statics.getPaginatedActivity = async function(limit: number, offs
|
|
|
return paginateResult;
|
|
|
};
|
|
|
|
|
|
-activitySchema.statics.findSnapshotUsernamesByUsernameRegex = async function(q: string, option) {
|
|
|
+// eslint-disable-next-line max-len
|
|
|
+activitySchema.statics.findSnapshotUsernamesByUsernameRegex = async function(q: string, option: { sortOpt: number | string, offset: number, limit: number}): Promise<{usernames: string[], totalCount: number}> {
|
|
|
const opt = option || {};
|
|
|
- const sortOpt = opt.sortOpt || { _id: 1 };
|
|
|
+ const sortOpt = opt.sortOpt || 1;
|
|
|
const offset = opt.offset || 0;
|
|
|
const limit = opt.limit || 10;
|
|
|
|
|
|
@@ -127,7 +128,7 @@ activitySchema.statics.findSnapshotUsernamesByUsernameRegex = async function(q:
|
|
|
const usernames = await this.aggregate()
|
|
|
.match(conditions)
|
|
|
.group({ _id: '$snapshot.username' })
|
|
|
- .sort(sortOpt)
|
|
|
+ .sort({ _id: sortOpt }) // Sort "snapshot.username" in ascending order
|
|
|
.skip(offset)
|
|
|
.limit(limit);
|
|
|
|