Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(species context): remove species count queries #169

Merged
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 11 additions & 11 deletions src/context/SpeciesContext.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,18 +34,18 @@ export function SpeciesProvider(props) {
const species = await api.getSpecies(abortController);
log.debug('load species from api:', species.length);

const speciesListWithCount = await Promise.all(
species.map(async (species) => {
let captureCount = await api.getCaptureCountPerSpecies(
species.id,
abortController,
);
species.captureCount = captureCount?.count;
return species;
}),
);
// const speciesListWithCount = await Promise.all(
Copy link
Contributor Author

@Mloweedgar Mloweedgar Oct 8, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@nmcharlton I have seen that this function makes many http request to get species counts, but the species object already carries the count information, I see no need for these requests. I would like to get your thoughts on this approach...

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right. The change you describe was made to the API in support of #115, so the speciesListWithCount bits can be removed.

// species.map(async (species) => {
// let captureCount = await api.getCaptureCountPerSpecies(
// species.id,
// abortController,
// );
// species.captureCount = captureCount?.count;
// return species;
// }),
// );
// console.log('species with count', speciesListWithCount);
setSpeciesList(speciesListWithCount);
setSpeciesList(species);
};

// only used by Species dropdown
Expand Down