Skip to content
This repository was archived by the owner on Dec 7, 2022. It is now read-only.

Commit 34927a9

Browse files
refactor: simplify batching
1 parent 954bbd7 commit 34927a9

File tree

1 file changed

+6
-8
lines changed

1 file changed

+6
-8
lines changed

src/model/YouTrack.ts

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -169,24 +169,22 @@ export class YouTrack {
169169
const top = 30;
170170
const result = new Array<U>();
171171
let skip = 0;
172-
let batch = await this.getBatch<T, U>(path, skip, top, params);
173-
result.push(...batch);
174172

175-
while (batch.length === top) {
173+
while (await this.appendBatch<T, U>(result, path, skip, top, params)) {
176174
skip += top;
177-
batch = await this.getBatch<T, U>(path, skip, top, params);
178-
result.push(...batch);
179175
}
180176

181177
return result;
182178
}
183179

184-
private getBatch<T extends U[], U>(
185-
path: string, skip: number, top: number, params?: Array<[string, string]>) {
180+
private async appendBatch<T extends U[], U>(
181+
result: U[], path: string, skip: number, top: number, params?: Array<[string, string]>) {
186182
const batchParams = [...(params || [])];
187183
batchParams.push(["$skip", skip.toString()], ["$top", top.toString()]);
184+
const batch = await this.get<T>(path, batchParams);
185+
result.push(...batch);
188186

189-
return this.get<T>(path, batchParams);
187+
return batch.length === top;
190188
}
191189

192190
private post<T>(path: string, params?: Array<[ string, string ]>, body?: unknown) {

0 commit comments

Comments
 (0)