From 40585f7d0092d82a1726569d03d04dad4fe0c6c1 Mon Sep 17 00:00:00 2001 From: Boldizsar Mezei Date: Wed, 14 Feb 2024 22:49:37 +0100 Subject: [PATCH] Fix get grouped map key --- packages/sdk/src/https/get/GetByIdGrouped.ts | 6 +++--- packages/sdk/src/https/get/GetByIdGroupedLive.ts | 7 +++---- packages/sdk/src/https/get/common.ts | 6 +++--- 3 files changed, 9 insertions(+), 10 deletions(-) diff --git a/packages/sdk/src/https/get/GetByIdGrouped.ts b/packages/sdk/src/https/get/GetByIdGrouped.ts index fa658646e5..5a16a118d5 100644 --- a/packages/sdk/src/https/get/GetByIdGrouped.ts +++ b/packages/sdk/src/https/get/GetByIdGrouped.ts @@ -11,11 +11,11 @@ export class GetByIdGroupedClass extends AbstractGetByIdGrouped { if (this.requests.length >= BATCH_MAX_SIZE) { await this.executeRequests(); - return this.result[request.setId + request.subsetId]! as T | undefined; + return this.result[this.toKey(request)] as T | undefined; } await this.executeTimed(); - return this.result[request.setId + request.subsetId]! as T | undefined; + return this.result[this.toKey(request)] as T | undefined; }; protected executeRequests = async () => { @@ -24,7 +24,7 @@ export class GetByIdGroupedClass extends AbstractGetByIdGrouped { const response = await wrappedFetch(requests[0].apiKey, url, params); const source = Array.isArray(response) ? response : [response]; for (const r of requests) { - this.result[r.setId + r.subsetId] = source.find((d) => + this.result[this.toKey(r)] = source.find((d) => [get(d, 'uid', ''), get(d, 'id', '')].includes(r.subsetId || r.setId), ); } diff --git a/packages/sdk/src/https/get/GetByIdGroupedLive.ts b/packages/sdk/src/https/get/GetByIdGroupedLive.ts index fe66013e5e..638b54680d 100644 --- a/packages/sdk/src/https/get/GetByIdGroupedLive.ts +++ b/packages/sdk/src/https/get/GetByIdGroupedLive.ts @@ -13,11 +13,10 @@ export class GetByIdGroupedLiveClass extends AbstractGetByIdGrouped { if (this.requests.length >= BATCH_MAX_SIZE) { await this.executeRequests(); - return this.observers[request.setId + request.subsetId]! as Observable; + return this.observers[this.toKey(request)] as Observable; } - await this.executeTimed(); - return this.observers[request.setId + request.subsetId]! as Observable; + return this.observers[this.toKey(request)] as Observable; }; protected executeRequests = async () => { @@ -28,7 +27,7 @@ export class GetByIdGroupedLiveClass extends AbstractGetByIdGrouped { map((r) => (Array.isArray(r) ? r : [r])), ); for (const r of requests) { - this.observers[r.setId + r.subsetId] = source.pipe( + this.observers[this.toKey(r)] = source.pipe( map((s) => { const id = r.subsetId || r.setId; return s.find((d) => [get(d, 'uid', ''), get(d, 'id', '')].includes(id)); diff --git a/packages/sdk/src/https/get/common.ts b/packages/sdk/src/https/get/common.ts index 182ec30d68..671748d045 100644 --- a/packages/sdk/src/https/get/common.ts +++ b/packages/sdk/src/https/get/common.ts @@ -24,10 +24,10 @@ export abstract class AbstractGroupedGet { protected requests: Request[] = []; protected timer: Promise | null = null; + protected toKey = (r: Request) => r.dataset + r.setId + r.subset + r.subsetId; + protected init = (request: Request) => { - const existing = this.requests.find( - (r) => r.setId === request.setId && r.subsetId === request.subsetId, - ); + const existing = this.requests.find((r) => this.toKey(r) === this.toKey(request)); if (!existing) { this.requests.push(request); }