Skip to content

Commit

Permalink
refactor: 🐛 값이 0일때를 고려해 null처리 변경 || -> ??, push에서 스프레드연산자로 변경
Browse files Browse the repository at this point in the history
  • Loading branch information
niamu01 committed Mar 12, 2024
1 parent e8550b5 commit 7a5e8e6
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions app/src/feed/feed.cache.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,16 @@ export class FeedCacheService {
private feedCache = new Map<number, (typeof FeedUnion)[]>();

async get(userId: number): Promise<(typeof FeedUnion)[]> {
return this.feedCache.get(userId) || [];
return this.feedCache.get(userId) ?? [];
}

async set(userId: number, feed: (typeof FeedUnion)[]): Promise<void> {
this.feedCache.set(userId, feed);
}

async writeFeed(userId: number, feed: typeof FeedUnion): Promise<void> {
const cachedFeedList = await this.get(userId);
cachedFeedList.push(feed);
await this.set(userId, cachedFeedList);
const prev = await this.get(userId);

await this.set(userId, [...prev, feed]);
}
}

0 comments on commit 7a5e8e6

Please sign in to comment.