Skip to content

Commit

Permalink
Parallelize fetching vendor components
Browse files Browse the repository at this point in the history
  • Loading branch information
bhollis committed Jun 21, 2024
1 parent 0275d64 commit 363401f
Showing 1 changed file with 29 additions and 19 deletions.
48 changes: 29 additions & 19 deletions src/app/vendors/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,28 +111,38 @@ export function loadAllVendors(
);

const vendorResponses: [vendorHash: number, DestinyVendorResponse][] = [];
const promises: Promise<void>[] = [];
for (const vendorHash of vendorsNeedingComponents) {
try {
start = Date.now();
const vendorResponse = await getVendorSaleComponents(account, characterId, vendorHash);
timings.componentsTime += Date.now() - start;
timings.componentsFetched++;
if (isVendorsPage) {
dispatch(
loadedVendorComponents({
vendorResponses: [[vendorHash, vendorResponse]],
promises.push(
(async () => {
try {
start = Date.now();
const vendorResponse = await getVendorSaleComponents(
account,
characterId,
}),
);
} else {
vendorResponses.push([vendorHash, vendorResponse]);
}
} catch {
// TO-DO: what to do here if a single vendor component call fails?
// not necessarily knock the overall vendors state into error mode.
// maybe retry failed single-vendors later? add them to a new list in vendors state?
}
vendorHash,
);
timings.componentsTime += Date.now() - start;
timings.componentsFetched++;
if (isVendorsPage) {
dispatch(
loadedVendorComponents({
vendorResponses: [[vendorHash, vendorResponse]],
characterId,
}),
);
} else {
vendorResponses.push([vendorHash, vendorResponse]);
}
} catch {
// TO-DO: what to do here if a single vendor component call fails?
// not necessarily knock the overall vendors state into error mode.
// maybe retry failed single-vendors later? add them to a new list in vendors state?
}
})(),
);
}
await Promise.all(promises);
if (!isVendorsPage) {
dispatch(loadedVendorComponents({ vendorResponses, characterId }));
}
Expand Down

0 comments on commit 363401f

Please sign in to comment.