Skip to content

Open Source Wealth Management Software. Angular + NestJS + Prisma + Nx + TypeScript 🤍

Task/improve performance of deleting watchlist item by loading only required data (#7908)

Thomas Kaulc180279106bd
diff --git a/CHANGELOG.md b/CHANGELOG.md
index c19f0f38ee..d2f55ca20c 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -15,6 +15,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Changed
- Localized the default account name created during user registration
+- Improved the performance of deleting a watchlist item
- Extended the `POST api/v1/user` endpoint by the language code
- Improved the language localization for German (`de`)
- Upgraded `@internationalized/number` from version `3.6.7` to `3.6.8`
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..53076b311c 100644
--- a/apps/api/src/app/endpoints/watchlist/watchlist.service.ts
+++ b/apps/api/src/app/endpoints/watchlist/watchlist.service.ts
@@ -152,4 +152,20 @@ 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({
+ where: {
+ dataSource,
+ symbol,
+ watchedBy: { some: { id: userId } }
+ }
+ });
+
+ return !!assetProfile;
+ }
}