-
Notifications
You must be signed in to change notification settings - Fork 1
Pr/optimize sidecar #83
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
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,77 @@ | ||
| """Tests for AppController._get_bulk_metadata_map error isolation. | ||
|
|
||
| The grid (ThumbnailModel.refresh_from_controller) treats a non-None metadata | ||
| map as authoritative — it does not fall back to per-image sidecar lookups on | ||
| miss. So per-image errors during bulk build must be isolated; one bad path | ||
| must not silently force every grid flag to false for the whole folder. | ||
| """ | ||
|
|
||
| from faststack.models import EntryMetadata, ImageFile | ||
|
|
||
|
|
||
| def _make_image(tmp_path, name): | ||
| p = tmp_path / name | ||
| p.write_bytes(b"\xff\xd8") | ||
| return ImageFile(path=p, timestamp=1000.0) | ||
|
|
||
|
|
||
| def test_per_image_error_does_not_invalidate_other_entries(app_controller, tmp_path): | ||
| """One sidecar.get_metadata raise must not drop other images from the map.""" | ||
| a = _make_image(tmp_path, "a.jpg") | ||
| bad = _make_image(tmp_path, "b.jpg") | ||
| c = _make_image(tmp_path, "c.jpg") | ||
| app_controller.image_files = [a, bad, c] | ||
|
|
||
| def fake_get_metadata(path, *, create): | ||
| if path == bad.path: | ||
| raise OSError("simulated sidecar failure for one image") | ||
| return EntryMetadata(favorite=True, uploaded=True) | ||
|
|
||
| app_controller.sidecar.get_metadata.side_effect = fake_get_metadata | ||
|
|
||
| bulk_map = app_controller._get_bulk_metadata_map() | ||
|
|
||
| assert str(a.path) in bulk_map | ||
| assert str(c.path) in bulk_map | ||
| assert str(bad.path) not in bulk_map | ||
| assert bulk_map[str(a.path)]["favorite"] is True | ||
| assert bulk_map[str(a.path)]["uploaded"] is True | ||
| assert bulk_map[str(c.path)]["favorite"] is True | ||
|
|
||
|
|
||
| def test_all_images_raise_yields_empty_map(app_controller, tmp_path): | ||
| """Documents the contract: when every lookup fails, the map is empty. | ||
|
|
||
| The grid treats this empty map as authoritative — the resulting all-false | ||
| flags are intentional, not a silent regression. Any future change to the | ||
| error-path contract should update this test. | ||
| """ | ||
| a = _make_image(tmp_path, "a.jpg") | ||
| b = _make_image(tmp_path, "b.jpg") | ||
| app_controller.image_files = [a, b] | ||
|
|
||
| app_controller.sidecar.get_metadata.side_effect = OSError("everything is broken") | ||
|
|
||
| bulk_map = app_controller._get_bulk_metadata_map() | ||
|
|
||
| assert bulk_map == {} | ||
|
|
||
|
|
||
| def test_first_image_raises_subsequent_succeed(app_controller, tmp_path): | ||
| """Earlier exceptions must not skip later images (regression for outer try).""" | ||
| bad = _make_image(tmp_path, "a.jpg") | ||
| good = _make_image(tmp_path, "b.jpg") | ||
| app_controller.image_files = [bad, good] | ||
|
|
||
| def fake_get_metadata(path, *, create): | ||
| if path == bad.path: | ||
| raise RuntimeError("first one fails") | ||
| return EntryMetadata(stacked=True) | ||
|
|
||
| app_controller.sidecar.get_metadata.side_effect = fake_get_metadata | ||
|
|
||
| bulk_map = app_controller._get_bulk_metadata_map() | ||
|
|
||
| assert str(bad.path) not in bulk_map | ||
| assert str(good.path) in bulk_map | ||
| assert bulk_map[str(good.path)]["stacked"] is True |
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
Oops, something went wrong.
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.
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.
Use canonical sidecar keys here to avoid cross-consumer metadata misses.
On Line 2628, keying
bulk_mapbystr(img.path)breaks the established contract for this method and can cause lookup mismatches where consumers rely on canonical sidecar keys.Suggested fix
Based on learnings: In
faststack.app.AppController._get_bulk_metadata_map, the dictionary must be keyed bySidecarManager.metadata_key_for_path(path)(the sidecar canonical key), not bynormalize_path_key(img.path), to avoid metadata lookup misses across consumers like the thumbnail model and folder stats.Also applies to: 2628-2628
🤖 Prompt for AI Agents