Add optional sharded on-disk layout for images and cache#52
Open
hauxir wants to merge 2 commits into
Open
Conversation
Flat IMAGES_DIR/CACHE_DIR directories become slow for readdir, backups, and cache sweeps once they hold millions of entries. When SHARD_STORAGE is enabled, files are stored under two 2-char subdirectories derived from the filename prefix (e.g. /images/ab/cd/abcd1234.jpg), keeping every directory small. URLs are unchanged — sharding is purely an on-disk detail. resolve_existing_path falls back to the flat location so mixed-era installs keep working; run app/migrate_shard.py once against each directory to relocate legacy flat files. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Review Summary by QodoAdd optional sharded on-disk layout for images and cache
WalkthroughsDescription• Implement optional sharded on-disk layout for images and cache directories • Add SHARD_STORAGE setting to organize files under 2-level subdirectories • Introduce resolve_path() and resolve_existing_path() helpers for path resolution • Create migration script to relocate existing flat files to sharded layout Diagramflowchart LR
A["File Upload/Request"] --> B{"SHARD_STORAGE<br/>Enabled?"}
B -->|No| C["Flat Layout<br/>/images/file.jpg"]
B -->|Yes| D["Sharded Layout<br/>/images/ab/cd/file.jpg"]
E["resolve_existing_path()"] --> F{"Check Flat<br/>First"}
F -->|Found| G["Return Flat Path"]
F -->|Not Found| H{"Check Sharded<br/>if Enabled"}
H -->|Found| I["Return Sharded Path"]
H -->|Not Found| J["Return None"]
K["migrate_shard.py"] --> L["Move Files to<br/>Sharded Layout"]
File Changes1. app/settings.py
|
Code Review by Qodo
1.
|
…ion collisions - Reject filenames that are not a plain basename in resolve_path and resolve_existing_path, closing a pre-existing path-traversal vector on GET and the newly-added cache write path. - delete_image now globs cached variants in both flat and sharded cache directories so mixed-era installs don't leave orphaned cache files. - migrate_shard.py skips existing targets, catches per-file OSError, and reports a failure count / non-zero exit so an interrupted or partial run can be re-run safely. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
SHARD_STORAGEsetting (default off). When enabled, files live under 2-level × 2-char subdirectories derived from the filename prefix, e.g./images/ab/cd/abcd1234.jpg.Tradeoffs / caveats
Test plan
🤖 Generated with Claude Code