-
Notifications
You must be signed in to change notification settings - Fork 4
[Feature] More efficient cache directory structure #681
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
Changes from all commits
d986920
da4c870
6b168c3
4ba5a24
e71b5df
5a3cfed
8281007
ab123dc
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -151,12 +151,9 @@ def _execute_task_with_cache( | |||||||||||||
fn_kwargs=task_dict["kwargs"], | ||||||||||||||
resource_dict=task_dict.get("resource_dict", {}), | ||||||||||||||
) | ||||||||||||||
os.makedirs(os.path.join(cache_directory, task_key), exist_ok=True) | ||||||||||||||
file_name = os.path.join(cache_directory, task_key, "cache.h5out") | ||||||||||||||
if not ( | ||||||||||||||
task_key in os.listdir(cache_directory) | ||||||||||||||
and "cache.h5out" in os.listdir(os.path.join(cache_directory, task_key)) | ||||||||||||||
): | ||||||||||||||
os.makedirs(cache_directory, exist_ok=True) | ||||||||||||||
file_name = os.path.join(cache_directory, task_key + "_o.h5") | ||||||||||||||
if task_key + "_o.h5" not in os.listdir(cache_directory): | ||||||||||||||
Comment on lines
+154
to
+156
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Prefer Using
- file_name = os.path.join(cache_directory, task_key + "_o.h5")
- if task_key + "_o.h5" not in os.listdir(cache_directory):
+ file_name = os.path.join(cache_directory, f"{task_key}_o.h5")
+ if not os.path.exists(file_name): 📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents
|
||||||||||||||
f = task_dict.pop("future") | ||||||||||||||
if f.set_running_or_notify_cancel(): | ||||||||||||||
try: | ||||||||||||||
|
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.
🛠️ Refactor suggestion
Use
exists()
instead of scanning the directory for every taskSimilar to the interactive path, scanning
os.listdir(cache_directory)
for each task does an unnecessary O(n) walk and risks TOCTOU issues.You already compute the same path a few lines later; reuse it to keep the logic DRY.
📝 Committable suggestion
🤖 Prompt for AI Agents