CLI binary download without include_binary; parallelize HTTP downloads#5587
Draft
CLI binary download without include_binary; parallelize HTTP downloads#5587
Conversation
This PR addresses several inefficiencies in binary data download logic: 1. **Remove IncludeBinary parameter usage**: Always download binary data via HTTP using the URI from metadata, since [IncludeBinary is considered harmful](https://docs.google.com/document/d/1Ex2wnnNp5rKiwb6RJz_ruViFTmeRTi8F9X6CjcW0QKM/edit?tab=t.0). 2. **Eliminate redundant metadata fetching**: - Filter-based downloads previously fetched metadata twice (once in getMatchingBinaryIDs, discarded, then again in downloadBinary). - Dataset downloads fetched metadata three times (once for IDs, once in downloadBinary, once in binaryDataToJSONLines). - Now all paths collect metadata once and reuse it. 3. **Parallelize downloads for ID-based path**: Previously sequential downloads when multiple IDs were provided; now uses worker pool pattern similar to filter-based downloads. 4. **Unify download logic**: Both filter-based and ID-based paths now use the same parallel download implementation via downloadBinaryFilesInParallel. Key changes: - Created downloadSingleBinaryFile: Extracts single-file download logic (metadata JSON writing, HTTP download with retry, file writing, gzip handling). - Created downloadBinaryFilesInParallel: Reusable parallel download function using worker pool pattern for both download paths. - Replaced getMatchingBinaryIDs with getMatchingBinaryMetadata: Returns full BinaryData objects with metadata (including URIs) instead of just IDs. - Refactored binaryData (filter-based): Collects all metadata once, then downloads in parallel. - Refactored dataExportBinaryIDsAction (ID-based): Collects all metadata once, then downloads in parallel. - Refactored downloadDataset: Eliminates triple metadata fetching, downloads files and writes JSON lines in parallel. - Removed deprecated downloadBinary function: No longer needed after refactor. Benefits: - Removed IncludeBinary usage to prefer the HTTP file server download. - Overall reduction in metadata API calls across download actions. - Significant performance improvement for ID-based downloads (now parallelized). - Consistent behavior across all download paths.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR addresses several inefficiencies in binary data download logic:
getMatchingBinaryIDs, discarded, then again indownloadBinary).downloadBinary, once inbinaryDataToJSONLines).filter-based downloads.
downloadBinaryFilesInParallel.Key changes:
getMatchingBinaryIDswithgetMatchingBinaryMetadata: Returns fullBinaryDataobjects with metadata (including URIs) instead of just IDs.binaryData(filter-based): Collects all metadata once, then downloads in parallel.dataExportBinaryIDsAction(ID-based): Collects all metadata once, then downloads in parallel.downloadDataset: Eliminates triple metadata fetching, downloads files and writes JSON lines in parallel.downloadBinaryfunction: No longer needed after refactor.Benefits: