Skip to content

Commit

Permalink
perf(MoodByLocationForPeriod): checking query result status exerts le…
Browse files Browse the repository at this point in the history
…ss perf toll than checking isError and isPending separately
  • Loading branch information
benji6 committed Sep 15, 2024
1 parent 94e3eb1 commit 25c530c
Showing 1 changed file with 11 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,20 @@ export default function MoodByLocationForPeriod({ dateFrom, dateTo }: Props) {
let errorCount = 0;
let loadingCount = 0;
let successCount = 0;

for (let i = 0; i < reverseGeolocationResults.length; i++) {
const result = reverseGeolocationResults[i];
const { mood, location } =
normalizedMoods.byId[moodIdsWithLocationInPeriod[i]];
if (result.isError) errorCount++;
else if (result.isPending) loadingCount++;
const { data } = result;
if (!data) continue;
const { data, status } = reverseGeolocationResults[i];
if (status === "error") {
errorCount++;
continue;
}
if (status === "pending") {
loadingCount++;
continue;
}
successCount++;

const { mood, location } =
normalizedMoods.byId[moodIdsWithLocationInPeriod[i]];
const Place = data?.Results?.[0]?.Place;
const locationName = Place?.Municipality ?? Place?.Label;
if (!locationName) {
Expand Down

0 comments on commit 25c530c

Please sign in to comment.