From 781496383ba5eeca90dff61d7f9827ff9440d581 Mon Sep 17 00:00:00 2001 From: Thomas Kaul <4159106+dtslvr@users.noreply.github.com> Date: Thu, 16 Nov 2023 20:22:56 +0100 Subject: [PATCH] Bugfix/improve get range query in market data service (#2659) * Attempt to fix "too many bind variables in prepared statement, expected maximum of 32767" * Update changelog --- CHANGELOG.md | 6 +++++ .../market-data/market-data.service.ts | 24 +++++++++---------- 2 files changed, 18 insertions(+), 12 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e582465aa..c70d22f37 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## Unreleased + +### Fixed + +- Fixed the "too many bind variables in prepared statement" issue of the data range functionality (`getRange()`) in the market data service + ## 2.23.0 - 2023-11-15 ### Added diff --git a/apps/api/src/services/market-data/market-data.service.ts b/apps/api/src/services/market-data/market-data.service.ts index 01f8bb9aa..05172dfe1 100644 --- a/apps/api/src/services/market-data/market-data.service.ts +++ b/apps/api/src/services/market-data/market-data.service.ts @@ -64,7 +64,7 @@ export class MarketDataService { dateQuery: DateQuery; uniqueAssets: UniqueAsset[]; }): Promise { - return await this.prismaService.marketData.findMany({ + return this.prismaService.marketData.findMany({ orderBy: [ { date: 'asc' @@ -74,17 +74,17 @@ export class MarketDataService { } ], where: { - OR: uniqueAssets.map(({ dataSource, symbol }) => { - return { - AND: [ - { - dataSource, - symbol, - date: dateQuery - } - ] - }; - }) + dataSource: { + in: uniqueAssets.map(({ dataSource }) => { + return dataSource; + }) + }, + date: dateQuery, + symbol: { + in: uniqueAssets.map(({ symbol }) => { + return symbol; + }) + } } }); }