Skip to content

Commit

Permalink
Fix get grouped map key
Browse files Browse the repository at this point in the history
  • Loading branch information
Boldizsar Mezei committed Feb 14, 2024
1 parent 23dd2de commit 40585f7
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 10 deletions.
6 changes: 3 additions & 3 deletions packages/sdk/src/https/get/GetByIdGrouped.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 () => {
Expand All @@ -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),
);
}
Expand Down
7 changes: 3 additions & 4 deletions packages/sdk/src/https/get/GetByIdGroupedLive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<T | undefined>;
return this.observers[this.toKey(request)] as Observable<T | undefined>;
}

await this.executeTimed();
return this.observers[request.setId + request.subsetId]! as Observable<T | undefined>;
return this.observers[this.toKey(request)] as Observable<T | undefined>;
};

protected executeRequests = async () => {
Expand All @@ -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));
Expand Down
6 changes: 3 additions & 3 deletions packages/sdk/src/https/get/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ export abstract class AbstractGroupedGet {
protected requests: Request[] = [];
protected timer: Promise<void> | 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);
}
Expand Down

0 comments on commit 40585f7

Please sign in to comment.