Skip to content

Commit 217ff56

Browse files
committed
Remove chunkIterable for now
1 parent 1d6824c commit 217ff56

File tree

1 file changed

+9
-41
lines changed

1 file changed

+9
-41
lines changed

src/higlass/widget.js

Lines changed: 9 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import { v4 } from "https://esm.sh/@lukeed/[email protected]";
44
/** @import { HGC, PluginDataFetcherConstructor, GenomicLocation, Viewconf, DataFetcher} from "./types.ts" */
55

66
const NAME = "jupyter";
7-
const MAX_TILES_PER_REQUEST = 20;
87

98
/**
109
* @param {string} href
@@ -207,29 +206,20 @@ async function registerJupyterHiGlassDataFetcher(model) {
207206
fetchTiles: consolidator(
208207
/** @param {Array<WithResolvers<{ tileIds: Array<string> }, Record<string, any>>>} requests */
209208
async (requests) => {
210-
const batches = await Promise.all(
211-
Array.from(
212-
chunkIterable(
213-
new Set(requests.flatMap((r) => r.data.tileIds)),
214-
MAX_TILES_PER_REQUEST,
215-
),
216-
async (tileIds) => {
217-
let response = await sendCustomMessage(tModel, {
218-
payload: { type: "tiles", tileIds },
219-
});
220-
return hgc.services.tileResponseToData(
221-
response.payload,
222-
NAME,
223-
tileIds,
224-
);
225-
},
226-
),
209+
let tileIds = [...new Set(requests.flatMap((r) => r.data.tileIds))];
210+
let response = await sendCustomMessage(tModel, {
211+
payload: { type: "tiles", tileIds },
212+
});
213+
let tiles = hgc.services.tileResponseToData(
214+
response.payload,
215+
NAME,
216+
tileIds,
227217
);
228218
for (let request of requests) {
229219
/** @type {Record<string, unknown>} */
230220
const requestData = {};
231221
for (let id of request.data.tileIds) {
232-
let tileData = batches.find((tile) => tile[id])?.[id];
222+
let tileData = tiles[id];
233223
if (tileData) requestData[id] = tileData;
234224
}
235225
request.resolve(requestData);
@@ -362,25 +352,3 @@ function consolidator(processBatch) {
362352
return promise;
363353
};
364354
}
365-
366-
/**
367-
* Iterator helper to chunk an array into smaller arrays of a fixed size.
368-
*
369-
* @template T
370-
* @param {Iterable<T>} iterable
371-
* @param {number} size
372-
* @returns {Generator<Array<T>, void, unknown>}
373-
*/
374-
function* chunkIterable(iterable, size) {
375-
let chunk = [];
376-
for (const item of iterable) {
377-
chunk.push(item);
378-
if (chunk.length === size) {
379-
yield chunk;
380-
chunk = [];
381-
}
382-
}
383-
if (chunk.length) {
384-
yield chunk;
385-
}
386-
}

0 commit comments

Comments
 (0)