Skip to content

Commit

Permalink
use Promise.all for fetching statusEvents concurrently across remoteS…
Browse files Browse the repository at this point in the history
…ervers; update comment in StasusEvent updater
  • Loading branch information
eriktaubeneck committed Jul 19, 2024
1 parent ac6223b commit cfcb502
Showing 1 changed file with 15 additions and 9 deletions.
24 changes: 15 additions & 9 deletions server/app/query/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,10 @@ export default function Page() {
let _prev = prev;
if (!Object.hasOwn(prev, query.uuid)) {
// if queryID not in dataByQuery yet,
// add initial status before updating value
// add initial status before updating value.
// otherwise prev[query.uuid][statusEvent][remteServer.ServerName]
// doesn't exist, and cannot be updated. we need to fill in the
// nested structure, which `initialStatusEventByRemoteServer` does.
_prev = {
..._prev,
[query.uuid]: {
Expand Down Expand Up @@ -81,15 +84,18 @@ export default function Page() {
);
});

for (const queryID of queryIDs) {
const promises = queryIDs.map(async (queryID) => {
const query: Query = await getQueryByUUID(queryID);

for (const remoteServer of Object.values(IPARemoteServers)) {
const statusEvent: StatusEvent =
await remoteServer.queryStatus(queryID);
updateData(query, remoteServer, statusEvent);
}
}
const remoteServerPromises = Object.values(IPARemoteServers).map(
async (remoteServer) => {
const statusEvent: StatusEvent =
await remoteServer.queryStatus(queryID);
updateData(query, remoteServer, statusEvent);
},
);
await Promise.all(remoteServerPromises);
});
await Promise.all(promises);
})();
}, [queryIDs]);

Expand Down

0 comments on commit cfcb502

Please sign in to comment.