Skip to content

Commit

Permalink
Parallel requests
Browse files Browse the repository at this point in the history
In theory this should be the fix for the rate limit. ref. replugged-org#586
  • Loading branch information
Chri6s committed Dec 7, 2023
1 parent 5b5b4f1 commit 1745ce0
Showing 1 changed file with 26 additions and 4 deletions.
30 changes: 26 additions & 4 deletions src/renderer/managers/updater.ts
Original file line number Diff line number Diff line change
Expand Up @@ -219,10 +219,32 @@ export async function checkAllUpdates(autoCheck = false, verbose = false): Promi

logger.log("Checking for updates");

await Promise.all([
checkUpdate(REPLUGGED_ID, verbose),
...addons.map((addon) => checkUpdate(addon.manifest.id, verbose)),
]);
const delay = (ms: number): Promise<void> => new Promise((resolve) => setTimeout(resolve, ms));
async function checkUpdatesWithRateLimit(): Promise<void> {
await checkUpdate(REPLUGGED_ID, verbose);
let requests = [];
let addonCount = 0;

for (const addon of addons) {
requests.push(checkUpdate(addon.manifest.id, verbose));
addonCount++;

if (addonCount === 15) {
addonCount = 0;
try {

await Promise.all(requests)
} catch (error) {

throw new Error(`Updater threw error:\n ${error}`);
}

await delay(1000); // Delay for 1 second after sending 15 requests
}
}
}

await checkUpdatesWithRateLimit();

logger.log("All updates checked");
updaterSettings.set("lastChecked", Date.now());
Expand Down

0 comments on commit 1745ce0

Please sign in to comment.