Browse Source

Improve performance of deleting watchlist item

pull/7908/head
Thomas Kaul 4 weeks ago
parent
commit
6ed841aae3
  1. 11
      apps/api/src/app/endpoints/watchlist/watchlist.controller.ts
  2. 17
      apps/api/src/app/endpoints/watchlist/watchlist.service.ts

11
apps/api/src/app/endpoints/watchlist/watchlist.controller.ts

@ -52,14 +52,13 @@ export class WatchlistController {
@Param('dataSource') dataSource: DataSource, @Param('dataSource') dataSource: DataSource,
@Param('symbol') symbol: string @Param('symbol') symbol: string
) { ) {
const watchlistItems = const hasWatchlistItem = await this.watchlistService.hasWatchlistItem({
await this.watchlistService.getWatchlistItems(userId); dataSource,
symbol,
const watchlistItem = watchlistItems.find((item) => { userId
return item.dataSource === dataSource && item.symbol === symbol;
}); });
if (!watchlistItem) { if (!hasWatchlistItem) {
throw new HttpException( throw new HttpException(
getReasonPhrase(StatusCodes.NOT_FOUND), getReasonPhrase(StatusCodes.NOT_FOUND),
StatusCodes.NOT_FOUND StatusCodes.NOT_FOUND

17
apps/api/src/app/endpoints/watchlist/watchlist.service.ts

@ -152,4 +152,21 @@ export class WatchlistService {
return a.name.localeCompare(b.name); return a.name.localeCompare(b.name);
}); });
} }
public async hasWatchlistItem({
dataSource,
symbol,
userId
}: { userId: string } & AssetProfileIdentifier): Promise<boolean> {
const assetProfile = await this.prismaService.symbolProfile.findFirst({
select: { id: true },
where: {
dataSource,
symbol,
watchedBy: { some: { id: userId } }
}
});
return !!assetProfile;
}
} }

Loading…
Cancel
Save