From 6ed841aae370875ed57b213cbb0a95481087d39f Mon Sep 17 00:00:00 2001 From: Thomas Kaul <4159106+dtslvr@users.noreply.github.com> Date: Sat, 19 Sep 2026 12:21:59 +0200 Subject: [PATCH] Improve performance of deleting watchlist item --- .../endpoints/watchlist/watchlist.controller.ts | 11 +++++------ .../endpoints/watchlist/watchlist.service.ts | 17 +++++++++++++++++ 2 files changed, 22 insertions(+), 6 deletions(-) diff --git a/apps/api/src/app/endpoints/watchlist/watchlist.controller.ts b/apps/api/src/app/endpoints/watchlist/watchlist.controller.ts index d833981392..b9250833ec 100644 --- a/apps/api/src/app/endpoints/watchlist/watchlist.controller.ts +++ b/apps/api/src/app/endpoints/watchlist/watchlist.controller.ts @@ -52,14 +52,13 @@ export class WatchlistController { @Param('dataSource') dataSource: DataSource, @Param('symbol') symbol: string ) { - const watchlistItems = - await this.watchlistService.getWatchlistItems(userId); - - const watchlistItem = watchlistItems.find((item) => { - return item.dataSource === dataSource && item.symbol === symbol; + const hasWatchlistItem = await this.watchlistService.hasWatchlistItem({ + dataSource, + symbol, + userId }); - if (!watchlistItem) { + if (!hasWatchlistItem) { throw new HttpException( getReasonPhrase(StatusCodes.NOT_FOUND), StatusCodes.NOT_FOUND diff --git a/apps/api/src/app/endpoints/watchlist/watchlist.service.ts b/apps/api/src/app/endpoints/watchlist/watchlist.service.ts index 88702da007..91c7a61e25 100644 --- a/apps/api/src/app/endpoints/watchlist/watchlist.service.ts +++ b/apps/api/src/app/endpoints/watchlist/watchlist.service.ts @@ -152,4 +152,21 @@ export class WatchlistService { return a.name.localeCompare(b.name); }); } + + public async hasWatchlistItem({ + dataSource, + symbol, + userId + }: { userId: string } & AssetProfileIdentifier): Promise { + const assetProfile = await this.prismaService.symbolProfile.findFirst({ + select: { id: true }, + where: { + dataSource, + symbol, + watchedBy: { some: { id: userId } } + } + }); + + return !!assetProfile; + } }