Skip to content

Refactoring photo-album relation#3359

Merged
ildyria merged 4 commits intomasterfrom
refactoring-photo-album-relation
Jun 11, 2025
Merged

Refactoring photo-album relation#3359
ildyria merged 4 commits intomasterfrom
refactoring-photo-album-relation

Conversation

@ildyria
Copy link
Copy Markdown
Member

@ildyria ildyria commented May 18, 2025

Closes #1095

Drops the album_id attribute from the 'photos` table and create a relation table to allow a photo to be related to multiple albums.

This pull request introduces significant changes to the handling of photo and album operations, focusing on improving database integrity, optimizing queries, and enhancing maintainability. Key updates include refactoring the Delete and Merge actions for albums, modifying the PositionData logic, and restructuring photo deletion to better handle relationships and constraints.

Album and Photo Deletion Refactor:

  • Removed logic for handling unsorted albums directly in app/Actions/Album/Delete.php. Simplified the deletion process by delegating photo and album relationship handling to the PhotoDelete class, which now accepts an optional from_id parameter for improved flexibility. [1] [2] [3]
  • Added validation and helper methods in app/Actions/Photo/Delete.php to ensure arguments are consistent and to collect photos based on their album relationships. This includes methods like collectUnsortedPhotos, collectPhotosInAlbums, and collectPhotosInAlbumsByAlbumID. [1] [2]
  • Removed redundant logic for collecting size variants and live photo paths by album IDs, consolidating these operations to focus on photo IDs instead. [1] [2]

Album Merging Enhancements:

  • Updated the Merge action in app/Actions/Album/Merge.php to handle many-to-many relationships between photos and albums using the PA::PHOTO_ALBUM table. This avoids duplicate entries by deleting existing links before inserting new ones.

Position Data Updates:

  • Changed the PositionData logic in app/Actions/Album/PositionData.php and app/Actions/Albums/PositionData.php to use the albums relationship instead of album. This aligns with the shift to many-to-many relationships. [1] [2]
  • Modified the PositionDataResource constructor calls to reflect these changes. [1] [2]

Database Integrity and Diagnostics:

  • Updated the DBIntegrityCheck pipe in app/Actions/Diagnostics/Pipes/Checks/DBIntegrityCheck.php to use the albums relationship when checking for photos without originals. This ensures compatibility with the new data model.

Miscellaneous Improvements:

  • Simplified photo creation pipelines in app/Actions/Photo/Create.php by splitting SetParentAndOwnership into SetParent and SetOwnership. This improves modularity and clarity. [1] [2] [3]

@ildyria ildyria requested a review from a team as a code owner May 18, 2025 20:19
@ildyria ildyria added the Review: hard Difficult review expected: major changes, lots of files modified, and dependencies updated. label May 18, 2025
@ildyria ildyria requested review from Copilot and removed request for a team May 18, 2025 20:19
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This pull request refactors the relations between photos and albums by removing the direct album_id association and replacing it with a many-to-many relationship. Key changes include updating queries in several actions (e.g. Statistics, RSS, DuplicateFinder), splitting the responsibilities previously handled by SetParentAndOwnership into SetParent and SetOwnership, and modifying deletion and merging logic to work with the new PA::PHOTO_ALBUM table.

Reviewed Changes

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

Show a summary per file
File Description
app/Actions/Statistics/Spaces.php Updated join queries to use the new many-to-many relationship
app/Actions/Search/PhotoSearch.php Replaced the 'album' relation with 'albums' for photo queries
app/Actions/RSS/Generate.php Refactored feed item creation to match updated data handling
app/Actions/Photo/Pipes/Shared/SetParent.php Added new file to handle linking photos to albums via the relation
app/Actions/Photo/Pipes/Shared/SetOwnership.php Added new file to separately set photo ownership
app/Actions/Photo/Pipes/Shared/NotifyAlbums.php Adjusted album notification logic using DB count instead of album_id check
app/Actions/Photo/Pipes/Init/FindLivePartner.php Updated to use many-to-many join conditions for live partner lookup
app/Actions/Photo/MoveOrDuplicate.php Implements new linking logic for moving or duplicating photos
app/Actions/Photo/DuplicateFinder.php Updated duplicate finding queries to leverage the new relation
app/Actions/Photo/Delete.php Refactored deletion logic, adding argument validation and relation cleanup
app/Actions/Photo/Create.php Updated photo creation pipelines to use SetParent and SetOwnership instead of the removed SetParentAndOwnership
app/Actions/Diagnostics/Pipes/Checks/DBIntegrityCheck.php Modified integrity check queries to use the new albums relationship
app/Actions/Albums/PositionData.php Adjusted photo position data queries and resource instantiation
app/Actions/Album/PositionData.php Changed relation type to BelongsToMany and updated resource parameters
app/Actions/Album/Merge.php Refactored merging logic to use the many-to-many table without duplicates
app/Actions/Album/Delete.php Updated album deletion logic to delegate photo cleanup to PhotoDelete with revised arguments

Comment thread app/Actions/Albums/PositionData.php Outdated
Comment thread app/Actions/Photo/Delete.php
Comment thread app/Actions/Album/PositionData.php
@codecov
Copy link
Copy Markdown

codecov Bot commented May 18, 2025

Codecov Report

Attention: Patch coverage is 91.33127% with 28 lines in your changes missing coverage. Please review.

Project coverage is 86.66%. Comparing base (5484dee) to head (2b373db).
Report is 6 commits behind head on master.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@ildyria ildyria force-pushed the refactoring-livestats branch from a745953 to 9e97597 Compare May 26, 2025 19:28
@ildyria ildyria force-pushed the refactoring-photo-album-relation branch from cb3cf0b to 9ba1a70 Compare May 26, 2025 19:28
@ildyria ildyria force-pushed the refactoring-livestats branch from 9e97597 to 659305c Compare May 28, 2025 16:44
@ildyria ildyria force-pushed the refactoring-photo-album-relation branch from 9ba1a70 to 916e593 Compare May 28, 2025 16:44
@ildyria ildyria force-pushed the refactoring-livestats branch from 659305c to 877f658 Compare May 28, 2025 18:21
@ildyria ildyria force-pushed the refactoring-photo-album-relation branch from 916e593 to bcca8f7 Compare May 28, 2025 18:24
@ildyria ildyria force-pushed the refactoring-livestats branch from a921deb to ecc738c Compare May 28, 2025 18:32
@ildyria ildyria force-pushed the refactoring-photo-album-relation branch from 6cbc89d to 6e39bb0 Compare May 28, 2025 18:33
Base automatically changed from refactoring-livestats to master June 8, 2025 08:42
@ildyria ildyria force-pushed the refactoring-photo-album-relation branch from 6e39bb0 to b68cb45 Compare June 8, 2025 08:53
Comment thread tests/Traits/CatchFailures.php
Comment thread app/Actions/Photo/MoveOrDuplicate.php Outdated
Comment thread app/Actions/Photo/MoveOrDuplicate.php Outdated
@ildyria ildyria merged commit d60921e into master Jun 11, 2025
35 checks passed
@ildyria ildyria deleted the refactoring-photo-album-relation branch June 11, 2025 12:13
adelairdragon added a commit to adelairdragon/rambutan that referenced this pull request Jul 29, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Review: hard Difficult review expected: major changes, lots of files modified, and dependencies updated.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Could you please add relation - one file to many albums

3 participants