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('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

17
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<boolean> {
const assetProfile = await this.prismaService.symbolProfile.findFirst({
select: { id: true },
where: {
dataSource,
symbol,
watchedBy: { some: { id: userId } }
}
});
return !!assetProfile;
}
}

Loading…
Cancel
Save