Exclude details from facility list API by defaut #1739
Conversation
We reduced the max page size to 50 a while ago so that the more expensive to build responses that include all the details required to generate CSV/Excel downlod do not exceed our the cloudfront timeout.
Serializing contributor fields and extended fields requires multiple database lookups and is expensive. We add a `detail` query parameter to the facilities list and only include the `contributors`, `contributor_fields`, and `extended_fields` in the serialized output if that `detail` parameter is set to true. This change creates a regressing in the CSV downloads because the additional fields are no longer available. That should be fixed in a future commit.
Previously we defaulted to returning the full details so previously loaded data was ready for CSV/Excel download. Now that we default to excluding those details we need to update the action chain to refetch facilities.
@@ -967,8 +959,14 @@ def list(self, request): | |||
context = {'request': request} | |||
|
|||
if page_queryset is not None: | |||
should_serialize_details = params.validated_data['detail'] | |||
exclude_fields = [ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a clever way to handle this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is (mostly?) working well for me. The search is running noticeably faster, and the extended fields are appearing correctly in the details and the download. I also have some custom contributor fields in my development database, and they downloaded/displayed correctly in conjunction with extended fields.
In regards to the counts bug: The count in the header says 102; the number of rows for CSV download was 102 on first try. The number of facilities actually returned when I count them manually is 152; the number of facilities in the XLSX download is 153. There is a 'loading more facilities' tab at the bottom, even though the all the items shown in the CSV have downloaded and there are more facilities than the count indicates. On a second CSV download attempt, I received 154 facilities and some new ones showed up at the bottom of the list in the sidebar (but it still says 102 and 'loading more'). I'm continuing to look into it.
Additional local testing results (will continue to add to this comment as I uncover things so as to not spam the PR):
I checked the larger downloaded file for duplicates and determined that there is a chunk of facilities that are duplicates. If we remove them, the XLSX contains the expected number of items. |
I believe I have a fix/fixes to prevent the extra facilities from showing up. When running repeated tests with options A and B I didn't see the bug happen, although of course with an inconsistent bug it can be difficult to be 100% certain.
Option B: Prevent the list from downloading more items when the download is occurring (this seems like a better option since it doesn't change the display behavior; the only issue is that then the 'more loading' stays up longer if you scroll down since the list download takes longer):
Option C: Run CSV detailed fetching on a completely different set of actions / redux state than the 'thin' fetching. Downside is that it's not a quick-fix solution, upside is that it feels more 'correct' in terms of handling the data. |
While a download is in progress infinite scroll events from the component showing the list were previously resulting in duplicate data being added to the CSV. We attempt to resolve the issue by disabling infinite scroll handling while downloading.
Thank you for your incredibly detailed diagnosis of the download issue. I agree that a rewrite of the download handling to use different actions and redux storage is a good design, but I went with the the I pushed up that fix for re-review. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good!
Thanks again for the detailed review. |
Serializing contributor fields and extended fields requires multiple database lookups and is expensive. We add a
detail
query parameter to the facilities list and only include thecontributors
,contributor_fields
, andextended_fields
in the serialized output if thatdetail
parameter is set to true.This change creates a regressing in the CSV downloads because the additional fields are no longer available. That should be fixed in a future commit.
Connects #1737
Demo
Quick search
Full download for CSV/Excel
Notes
While testing embedded map downloads I saw that there were contributor attributions in the fields. I opened #1741 to look into those.
Testing Instructions
./tools/batc_process {id}
Checklist
fixup!
commits have been squashed