Skip to content

Commit

Permalink
⚡ Improve episode thumbnail loading performances
Browse files Browse the repository at this point in the history
  • Loading branch information
Xen0Xys committed May 17, 2024
1 parent d4426ee commit 00878cf
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions src/modules/webtoon/webtoon/webtoon-database.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -264,13 +264,11 @@ export class WebtoonDatabaseService{
}
});
const episodeLines: EpisodeLineModel[] = [];
for(const episode of episodes){
const thumbnailData: Buffer | undefined = this.loadImage(episode.thumbnail.sum);
if(!thumbnailData)
throw new NotFoundException(`Thumbnail not found for episode ${episode.number}`);
const thumbnail: string = this.miscService.bufferToDataURL(thumbnailData);
episodeLines.push(new EpisodeLineModel(episode.id, episode.title, episode.number, thumbnail));
}
const episodeLinesPromises: Promise<EpisodeLineModel>[] = [];
for(const episode of episodes)
episodeLinesPromises.push(this.loadEpisodeLine(episode));
for(const promise of episodeLinesPromises)
episodeLines.push(await promise);
return {
episodes: episodeLines,
backgroundBanner: this.miscService.bufferToDataURL(this.loadImage(dbWebtoon.background_banner.sum)),
Expand All @@ -280,6 +278,14 @@ export class WebtoonDatabaseService{
} as EpisodesResponse;
}

private async loadEpisodeLine(episode: any): Promise<EpisodeLineModel>{
const thumbnailData: Buffer | undefined = this.loadImage(episode.thumbnail.sum);
if(!thumbnailData)
throw new NotFoundException(`Thumbnail not found for episode ${episode.number}`);
const thumbnail: string = this.miscService.bufferToDataURL(thumbnailData);
return new EpisodeLineModel(episode.id, episode.title, episode.number, thumbnail);
}

async getEpisodeImages(episodeId: number): Promise<EpisodeResponse>{
const episode = await this.prismaService.episodes.findFirst({
where: {
Expand Down

0 comments on commit 00878cf

Please sign in to comment.