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 },