-
Notifications
You must be signed in to change notification settings - Fork 22
optimize management api calls #110
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
Conversation
9a4dd3e to
18a1f4c
Compare
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.
Pull request overview
This PR optimizes the management API calls for the DOWNLOAD MODEL command by reducing redundant GET requests. Instead of making 3 GET calls per folder/file (one for listing, two for directory checks), the optimization enables passing file metadata along with listings, reducing calls to 1 per folder/file—a 67% reduction while maintaining the same functionality.
Key Changes:
- Added
return_objectsparameter tolistdirmethods to optionally returnFilesObjectinstances with metadata instead of just path strings - Refactored
download_folderinFileSpaceto use metadata from listings, eliminating redundantis_dir()API calls - Added internal
_download_filemethod with_skip_dir_checkparameter to avoid duplicate directory validation
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 7 comments.
| File | Description |
|---|---|
| singlestoredb/management/workspace.py | Added return_objects parameter to listdir method with type overloads; download_folder still uses old implementation |
| singlestoredb/management/files.py | Added return_objects parameter to listdir methods and optimized download_folder to use FilesObject metadata, eliminating redundant API calls |
| singlestoredb/fusion/handlers/files.py | Updated listdir calls to explicitly pass metadata parameter (contains bug: uses wrong parameter name) |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
@copilot open a new pull request to apply changes based on the comments in this thread |
…ption handling Co-authored-by: ajha-ss <[email protected]>
Fix type safety and documentation issues in management API optimization
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.
Pull request overview
Copilot reviewed 3 out of 3 changed files in this pull request and generated 4 comments.
Comments suppressed due to low confidence (1)
singlestoredb/management/workspace.py:649
- The optimization to reduce API calls is not implemented in this method. Unlike the corresponding method in files.py (lines 1160-1180), this implementation still uses
return_objects=Falseand callsis_dir(f)for each item, which makes an additional GET request per item. This defeats the purpose of the optimization described in the PR.
The method should be updated to match the pattern used in files.py:
- Use
return_objects=Trueto get FilesObject instances - Check
entry.type == 'directory'instead of callingis_dir(f) - Consider adding an internal
_download_filemethod with_skip_dir_checkparameter to avoid the is_dir check in download_file
for f in self.listdir(stage_path, recursive=True, return_objects=False):
if self.is_dir(f):
continue
target = os.path.normpath(os.path.join(local_path, f))
os.makedirs(os.path.dirname(target), exist_ok=True)
self.download_file(f, target, overwrite=overwrite)
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
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.
Thanks for working on this, the overall logic looks good to me. I will leave the Python implementation details to @kesmit13.
What's the test plan for this? Could you describe how you tested it and share the results? If possible, it would also be helpful to add test cases to the existing test suite.
kesmit13
left a comment
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.
The changes look fine. It would be nice if the new option was covered in the unit tests (singlestoredb/tests/test_management.py). There are existing tests for listdir that could be extended. It doesn't have to be a lot of changes, but having one check to make sure the return_objects=True flag actually works.
|
@nunogoncalves03
Screencast.from.2026-01-05.22-31-01.webmI will add test cases soon to the test suite. Thanks for your review. |
We are having redundant API calls to management API for the DOWNLOAD MODEL command.
We are making 3 GET calls for every folder/file , so total GET calls = 3 (for parent folder)+ 3*N (2 checks are redundant as they check if the path is a directory or not but that information is already available in the metadata so these calls can be skipped).
Optimization in this branch -
we make 1 GET call per folder/file so if there is 1 parent folder and N files inside it, total calls now will be 1+N
This reduces the number of calls to 1/3rd or 67% reduction while maintaining the same functionality.