Skip to content

Commit

Permalink
Updated course units fetcher for parallel requests
Browse files Browse the repository at this point in the history
  • Loading branch information
Adriano-7 committed Dec 30, 2024
1 parent a832cc4 commit c73b2ce
Showing 1 changed file with 16 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,25 +18,23 @@ class CourseUnitsInfoFetcher implements SessionDependantFetcher {
Session session,
int occurId,
) async {
Response? bestResponse;

for (final endpoint in getEndpoints(session)) {
final url = '$endpoint' 'mob_ucurr_geral.perfil';
try {
final response = await NetworkRouter.getWithCookies(
url,
{'pv_ocorrencia_id': occurId.toString()},
session,
);
final responses = await Future.wait(
getEndpoints(session)
.map((endpoint) => '$endpoint' 'mob_ucurr_geral.perfil')
.map(
(url) => NetworkRouter.getWithCookies(
url,
{'pv_ocorrencia_id': occurId.toString()},
session,
),
),
);

if (bestResponse == null ||
response.body.length > bestResponse.body.length) {
bestResponse = response;
}
} catch (_) {
continue;
}
}
final bestResponse = responses.fold<Response?>(
null,
(best, current) =>
current.body.length > (best?.body.length ?? 0) ? current : best,
);

return bestResponse != null
? parseSheet(bestResponse)
Expand Down

0 comments on commit c73b2ce

Please sign in to comment.