Shun Miyazawa 3 ani în urmă
părinte
comite
0665b8f1cf

+ 5 - 4
packages/app/src/server/models/activity.ts

@@ -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);
 

+ 1 - 1
packages/app/src/stores/user.tsx

@@ -40,7 +40,7 @@ export const useSWRxUsernames = (q: string, offset?: number, limit?: number, opt
   return useSWRImmutable(
     q != null ? ['/users/usernames', q, offset, limit, options] : null,
     (endpoint, q, offset, limit, options) => apiv3Get(endpoint, {
-      q, offset, limit, options: JSON.stringify(options),
+      q, offset, limit, options,
     }).then(result => result.data),
   );
 };