-
Notifications
You must be signed in to change notification settings - Fork 67
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
[SYNPY-1401] Prevent Repeated syn.get
calls in _help_walk
#1059
Conversation
Hello @BWMac! Thanks for opening this PR. We checked the lines you've touched for PEP 8 issues, and found:
|
Quality Gate passedThe SonarCloud Quality Gate passed, but some issues were introduced. 11 New issues |
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.
Changes lgtm!
Ran this sample script to verify everything in the project printed:
for directory_path, directory_names, file_name in synapseutils.walk(
syn=syn, synId="syn49637038"
):
for directory_name in directory_names:
print(
f"Directory ({directory_name[1]}): {directory_path[0]}/{directory_name[0]}"
)
for file in file_name:
print(f"({file[1]}): {directory_path[0]}/{file[0]}")
And no errors were received.
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.
🔥 Excellent - this is another great example of iterative improvement to the codebase.
|
||
|
||
# Helper function to hide the newpath parameter | ||
def _helpWalk( | ||
def _help_walk( |
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.
Nit: Not sure what I was thinking when I was writing this, but the _
is almost redundant with help
. I can imagine this could be _walk
, but... this is good. no action required. Just a thought in the future for naming functions.
@BryanFauble Thanks for testing, next time I will include a script/snippet to save reviewers the trouble. |
syn.get
calls in _help_walk
syn.get
calls in _help_walk
Problem:
It was reported recently that running
synapseutils.walk
on large projects in Synapse with many folders and subfolders was taking a very long time due tosyn.get
being executed on every recursive_helpWalk
call. Further, as pointed out by @linglp, this is unnecessary since we are also usingsyn.getChildren
which provides the same information about entity types.Solution:
Update
_helpWalk
to use the entities returned bysyn.getChildren
in the recursive function call. Specifically, repeated calls tosyn.get
are prevented by adding a new parameter that carries the starting entity into each recursive iteration.syn.get
is called once perwalk
call to initiate the process from the parent folder or project.Notes:
cache
interacts with generators._helpWalk
and its parameters were converted to using snake case