Browse Source

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

* Improve performance of deleting watchlist item

* Update changelog
pull/7909/head
Thomas Kaul 1 week ago
committed by GitHub
parent
commit
c180279106
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
  1. 1
      CHANGELOG.md
  2. 11
      apps/api/src/app/endpoints/watchlist/watchlist.controller.ts
  3. 16
      apps/api/src/app/endpoints/watchlist/watchlist.service.ts

1
CHANGELOG.md

@ -15,6 +15,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Changed ### Changed
- Localized the default account name created during user registration - 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 - Extended the `POST api/v1/user` endpoint by the language code
- Improved the language localization for German (`de`) - Improved the language localization for German (`de`)
- Upgraded `@internationalized/number` from version `3.6.7` to `3.6.8` - Upgraded `@internationalized/number` from version `3.6.7` to `3.6.8`

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

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

@ -152,4 +152,20 @@ 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({
where: {
dataSource,
symbol,
watchedBy: { some: { id: userId } }
}
});
return !!assetProfile;
}
} }

Loading…
Cancel
Save