From 9b0b35b8bbd88795cac1535d96da142919fdcc7a Mon Sep 17 00:00:00 2001 From: Viet Nguyen <3805254+vnugent@users.noreply.github.com> Date: Fri, 14 Jul 2023 20:12:35 +0200 Subject: [PATCH] fix: use media object lastUpdated for sorting (#342) --- src/model/MediaDataSource.ts | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/model/MediaDataSource.ts b/src/model/MediaDataSource.ts index 5e2c90a4..8e34c726 100644 --- a/src/model/MediaDataSource.ts +++ b/src/model/MediaDataSource.ts @@ -63,9 +63,17 @@ export default class MediaDataSource extends MongoDataSource { ...toIncludeMediaWithTagsOrNotfilters, { /** - * Sort by most recently uploaded media first + * Sort by most recently tags media */ - $sort: { createdAt: -1, _id: -1 } + $sort: { updatedAt: -1, _id: -1 } + }, + { + /** + * Limit the most recent list. While unlikely, it may be + * possible that most recent tags belong to one user. + * We want this number to be large (to pick up more users). + */ + $limit: 100 }, { $group: { @@ -75,6 +83,9 @@ export default class MediaDataSource extends MongoDataSource { mediaWithTags: { $push: '$$ROOT' } } }, + { + $sort: { 'mediaWithTags.0.updatedAt': -1 } + }, { $limit: safeMaxUsers },