Skip to content

Minimize api calls in listdir_withattributes - #126

Open
khsrali wants to merge 3 commits into
aiidateam:mainfrom
khsrali:increased_performance
Open

Minimize api calls in listdir_withattributes#126
khsrali wants to merge 3 commits into
aiidateam:mainfrom
khsrali:increased_performance

Conversation

@khsrali

@khsrali khsrali commented Jan 15, 2026

Copy link
Copy Markdown
Collaborator

No description provided.

Copilot AI left a comment

Copy link
Copy Markdown

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 listdir_withattributes method to reduce API calls by directly using the FirecREST list_files API instead of making separate calls for each file entry (listdir, get_attribute, and isdir). This performance improvement reduces N API calls to a single call where N is the number of files in the directory.

Changes:

  • Added _parse_permissions helper to convert permission strings to st_mode integers
  • Added _parse_timestamp helper to convert ISO timestamp strings to Unix timestamps
  • Refactored listdir_withattributes_async to use a single list_files API call and parse results directly
  • Added comprehensive test coverage for listdir_withattributes functionality

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
aiida_firecrest/transport.py Added helper methods for parsing file metadata and optimized listdir_withattributes_async to minimize API calls by using list_files directly
tests/test_transport.py Added comprehensive test for listdir_withattributes covering directories, files, symlinks, attributes validation, and pattern filtering

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +1433 to +1437
for i, char in enumerate(perms):
group_idx = i // 3
perm_idx = i % 3
if char != "-" and group_idx < 3 and perm_idx < 3:
mode |= perm_bits[group_idx][perm_idx]

Copilot AI Jan 15, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The permission parsing logic doesn't handle special permission bits (setuid, setgid, sticky bit). These are typically represented by characters like 's', 'S', 't', 'T' in the permission string (e.g., 'rwsr-xr-x' for setuid). The current implementation will set permission bits for any non-'-' character, which could lead to incorrect permission values. Consider adding explicit handling for these special characters or validating that only 'r', 'w', 'x' are processed.

Copilot uses AI. Check for mistakes.
Comment thread tests/test_transport.py
(_local / "file1").write_text("content")
transport.putfile(_local / "file1", _remote / "file1")
transport.chmod(_remote / "file1", 0o644)
transport.symlink(_remote / "file1", _remote / "link1")

Copilot AI Jan 15, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The test verifies that 'link1' appears in the results but doesn't validate the symlink's attributes or isdir flag. Consider adding assertions to verify that results_dict['link1']['isdir'] is False and that stat.S_ISLNK(results_dict['link1']['attributes'].st_mode) is True to ensure symlinks are correctly identified and their attributes properly set.

Copilot uses AI. Check for mistakes.
@codecov

codecov Bot commented Jan 16, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 94.59459% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 84.41%. Comparing base (f000725) to head (aa50526).

Files with missing lines Patch % Lines
aiida_firecrest/transport.py 94.59% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #126      +/-   ##
==========================================
+ Coverage   82.03%   84.41%   +2.38%     
==========================================
  Files           4        4              
  Lines         846      879      +33     
==========================================
+ Hits          694      742      +48     
+ Misses        152      137      -15     
Flag Coverage Δ
pytests 84.41% <94.59%> (+2.38%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants