Skip to content

Commit

Permalink
♻️ refactor: 트렌드 데이터 뷰를 통해 검색하도록 변경
Browse files Browse the repository at this point in the history
  • Loading branch information
Jo-Minseok committed Jan 2, 2025
1 parent 01d2d42 commit 2307892
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 15 deletions.
22 changes: 21 additions & 1 deletion server/src/feed/feed.repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ export class FeedViewRepository extends Repository<FeedView> {
super(FeedView, dataSource.createEntityManager());
}

async findFeed(queryFeedDto: QueryFeedDto) {
async findFeedPagination(queryFeedDto: QueryFeedDto) {
const { lastId, limit } = queryFeedDto;
const query = this.createQueryBuilder()
.select('feed_id', 'feedId')
Expand Down Expand Up @@ -96,4 +96,24 @@ export class FeedViewRepository extends Repository<FeedView> {

return await query.getRawMany();
}

async findFeedById(feedId: number) {
const feed = await this.createQueryBuilder()
.select('feed_id', 'id')
.addSelect('feed_title', 'title')
.addSelect('feed_path', 'path')
.addSelect('feed_created_at', 'createdAt')
.addSelect('feed_thumbnail', 'thumbnail')
.addSelect('feed_view_count', 'viewCount')
.addSelect('blog_name', 'author')
.addSelect('blog_platform', 'blogPlatform')
.where('feed_id = :feedId', { feedId })
.getRawOne();

if (!feed) {
return null;
}

return feed;
}
}
19 changes: 5 additions & 14 deletions server/src/feed/feed.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ export class FeedService {
) {}

async readFeedPagination(queryFeedDto: QueryFeedDto) {
const feedList = await this.feedViewRepository.findFeed(queryFeedDto);
const feedList =
await this.feedViewRepository.findFeedPagination(queryFeedDto);
const hasMore = this.existNextFeed(feedList, queryFeedDto.limit);
if (hasMore) feedList.pop();
const lastId = this.getLastIdFromFeedList(feedList);
Expand Down Expand Up @@ -71,19 +72,9 @@ export class FeedService {
-1,
);
const trendFeeds = await Promise.all(
trendFeedIdList.map(async (feedId) => {
const feed = await this.feedRepository.findOne({
where: { id: parseInt(feedId) },
relations: ['blog'],
});
if (!feed) {
return null;
}
feed['author'] = feed.blog['name'];
feed['blogPlatform'] = feed.blog['blogPlatform'];
delete feed.blog;
return feed;
}),
trendFeedIdList.map(async (feedId) =>
this.feedViewRepository.findFeedById(parseInt(feedId)),
),
);
return trendFeeds.filter((feed) => feed !== null);
}
Expand Down

0 comments on commit 2307892

Please sign in to comment.