Skip to content

Commit

Permalink
feat: 🐛 cache된 리스트를 반환할 때도 sort한 후 반환하도록 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
niamu01 committed Feb 20, 2024
1 parent 58db12b commit 90129d7
Showing 1 changed file with 17 additions and 5 deletions.
22 changes: 17 additions & 5 deletions app/src/follow/follow.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ export class FollowService {
'following',
);

cachedfollowingList.unshift({ userPreview: target, followAt });
cachedfollowingList.push({ userPreview: target, followAt });

await this.followCacheService.set({
id: userId,
Expand All @@ -93,7 +93,7 @@ export class FollowService {
throw new NotFoundException();
}

cachedfollowerList.unshift({ userPreview: user, followAt });
cachedfollowerList.push({ userPreview: user, followAt });

await this.followCacheService.set({
id: targetId,
Expand Down Expand Up @@ -236,10 +236,22 @@ export class FollowService {
);

if (cachedFollowingList.length) {
return await this.checkFollowing({
const followingList = await this.checkFollowing({
userId,
cachedFollowList: cachedFollowingList,
});

if (sortOrder === FollowSortOrder.FOLLOW_AT_ASC) {
followingList.sort(
(a, b) => a.followAt.getTime() - b.followAt.getTime(),
);
} else if (sortOrder === FollowSortOrder.FOLLOW_AT_DESC) {
followingList.sort(
(a, b) => b.followAt.getTime() - a.followAt.getTime(),
);
}

return followingList;
}

if (filter) {
Expand Down Expand Up @@ -407,8 +419,8 @@ export class FollowService {
const followSort = (sortOrder: FollowSortOrder): Record<string, SortOrder> => {
switch (sortOrder) {
case FollowSortOrder.FOLLOW_AT_ASC:
return { _id: 'asc' };
return { followAt: 'asc' };
case FollowSortOrder.FOLLOW_AT_DESC:
return { _id: 'desc' };
return { followAt: 'desc' };
}
};

0 comments on commit 90129d7

Please sign in to comment.