Skip to content

Add CHECK constraints and fix pagination/caching edge cases - #14

Open
T-One wants to merge 1 commit into
mainfrom
claude/repository-bug-analysis-h70mlu
Open

T-One wants to merge 1 commit into
mainfrom
claude/repository-bug-analysis-h70mlu

Conversation

@T-One

@T-One T-One commented Sep 1, 2026

Copy link
Copy Markdown
Owner

Summary

This PR adds database integrity constraints, fixes conditional HTTP caching for multi-tab scenarios, corrects filename tracking during ingestion, and improves lightbox pagination behavior.

Key Changes

Database (migration #2):

  • Add CHECK constraint to dev_status column to enforce valid values ('none', 'consideration', 'in_darkroom', 'developed')
  • Rebuild photos table using SQLite's standard 12-step procedure (table recreation with constraints)
  • Coalesce any pre-existing NULL values to 'none' during migration
  • Recreate all indexes after table rebuild

Backend API:

  • Extract _if_none_match_hits() helper to properly handle If-None-Match headers with comma-separated ETags and wildcard (*) values
    • Fixes 304 Not Modified responses in multi-tab scenarios where browsers may send multiple cached ETags
    • Applied to both /api/files/thumb/{photo_id} and /api/files/original/{photo_id} endpoints
  • Import SUPPORTED_RAW_EXTENSIONS from raw_processing module (cleanup)

Ingestion:

  • Track the actual stored filename after organize_path() collision resolution
    • Previously used the original filename, which could diverge from what was written to disk
    • Now uses stored_filename (resolved from dest_path) for DB record to keep filename in sync with filesystem
    • Fixes potential lookup failures in darkroom copy path and other filename-based operations

Frontend:

  • Fix lightbox "next" button availability: enable when selectedIndex < photos.length - 1 OR hasMore (infinite scroll case)
    • Previously disabled "next" at end of current page even if more photos exist on server
  • Pass rebuild status data to onRebuildComplete callback in Settings component
    • Allows parent component to react to rebuild completion details

Implementation Notes

  • Migration Add comprehensive CLAUDE.md for AI assistant guidance #2 uses COALESCE(dev_status, 'none') to safely handle any pre-existing NULL values
  • ETag matching now correctly handles browser prefetch/revalidation patterns (comma-separated list or *)
  • Filename resolution happens immediately after safe copy to ensure DB consistency with actual disk state

https://claude.ai/code/session_011ikgwwmNzbwMSFPLUpgSSn

- backend/main.py: import SUPPORTED_RAW_EXTENSIONS (was undefined,
  crashing every /api/upload call with a NameError)
- backend/ingestion.py: store the collision-resolved on-disk filename
  in the DB instead of the pre-resolution name, so two RAW files that
  share a basename no longer collide on their darkroom copy path
- backend/database.py: add migration v2 to enforce a CHECK constraint
  on dev_status (rebuilds the table since SQLite can't ALTER an
  existing column to add one), matching the documented schema
- backend/main.py: parse If-None-Match as a comma-separated ETag list
  instead of exact string match
- frontend/src/components/Settings.jsx: pass the final rebuild stats
  to onRebuildComplete so the toast shows the processed count
- frontend/src/App.jsx: keep the lightbox "Next" control available
  while more photos remain to be fetched (hasMore), not just while
  there's already a locally-loaded next photo

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_011ikgwwmNzbwMSFPLUpgSSn
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