Skip to content

Conversation

@lodewiges
Copy link
Contributor

@lodewiges lodewiges commented May 19, 2025

This PR makes it so the threshold for a photoalbum to be considerd tagged is moved to 85% instead of more than 1
Solves #564

Summary by CodeRabbit

  • Refactor
    • Updated album filtering to evaluate tag coverage per album (uses a coverage threshold), changing which albums are considered to have associated photos with tags.
    • As a result, lists and filters may show or hide a different set of albums compared to before; visible album listings and filter behavior may change accordingly.

@lodewiges lodewiges linked an issue May 19, 2025 that may be closed by this pull request
@codecov
Copy link

codecov bot commented May 19, 2025

Codecov Report

❌ Patch coverage is 0% with 3 lines in your changes missing coverage. Please review.
✅ Project coverage is 99.84%. Comparing base (8627531) to head (1bcee4a).
⚠️ Report is 10 commits behind head on staging.

Files with missing lines Patch % Lines
app/models/photo_album.rb 0.00% 3 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##           staging     #565      +/-   ##
===========================================
- Coverage    99.92%   99.84%   -0.08%     
===========================================
  Files          197      197              
  Lines         2658     2660       +2     
===========================================
  Hits          2656     2656              
- Misses           2        4       +2     

☔ View full report in Codecov by Sentry.
📢 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.

@coderabbitai
Copy link

coderabbitai bot commented Nov 4, 2025

Walkthrough

The without_photo_tags scope in PhotoAlbum was rewritten to use a subquery that joins albums → photos → tags, groups by album, computes the ratio of distinct tagged photos to distinct photos, and selects albums where that ratio is below 0.85; the scope signature is unchanged.

Changes

Cohort / File(s) Summary
PhotoAlbum scope refactor
app/models/photo_album.rb
Replaced a simple where.not(Photo.joins(:tags).select(:photo_album_id).distinct) exclusion with a subquery: unscoped join albums→photos→tags, GROUP BY photo_album_id, compute COUNT(DISTINCT tagged_photos) / COUNT(DISTINCT photos) and apply HAVING ratio < 0.85; public scope remains the same

Sequence Diagram(s)

sequenceDiagram
    autonumber
    participant App as App (PhotoAlbum scope)
    participant AR as ActiveRecord
    participant DB as Database

    App->>AR: build subquery (albums ← photos ← tags), group by album_id\nselect album_id where (COUNT(DISTINCT tagged_photos) / COUNT(DISTINCT photos)) < 0.85
    AR->>DB: execute SQL (JOIN + GROUP BY + HAVING)
    DB-->>AR: return album_ids
    AR-->>App: return ActiveRecord::Relation filtered by album_ids
    rect rgba(0,128,96,0.08)
      Note right of DB: HAVING computes per-album ratio and filters\n(ensure division by zero handled)
    end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

  • Pay special attention to:
    • Division-by-zero risk when counting photos per album.
    • Correctness of DISTINCT counts and HAVING arithmetic.
    • Performance of JOIN + GROUP BY on large tables and index usage.
    • Effects of using unscoped joins (default scopes / soft-delete bypass).

Poem

🐇 I hop through joins where tagged pixels hide,
I count each bounce and let ratios decide.
Subqueries hum beneath the moonlit logs—
Albums sifted gently like carrots from clogs.
A rabbit applauds this tidy SQL ride.

Pre-merge checks and finishing touches

❌ Failed checks (1 warning, 1 inconclusive)
Check name Status Explanation Resolution
Description check ⚠️ Warning The description is minimal and missing several required template sections including checklist items, detailed summary, and other relevant information about testing or dependencies. Complete the PR description by adding the checklist items, more detailed summary of changes, any UI/screenshot changes, and other relevant information as specified in the template.
Title check ❓ Inconclusive The title 'Improve Album suggestions SOG page' is vague and generic, lacking specific technical details about the actual change (threshold modification from >1 to 85%). Consider a more specific title that reflects the core change, such as 'Adjust album tagging threshold to 85%' or 'Update photo album tag ratio threshold for suggestions'.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch feature/improveSOGsuggestions

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 8627531 and cae374e.

📒 Files selected for processing (1)
  • app/models/photo_album.rb (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
  • GitHub Check: Lint
  • GitHub Check: Test

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (1)
app/models/photo_album.rb (1)

24-24: Prefer parameterized queries over string interpolation.

Direct interpolation of tag_percentage_threshold into the SQL string is not parameterized. While the variable is currently a local constant, this pattern could introduce SQL injection vulnerabilities if later refactored to accept external input.

Consider using Arel or a parameterized placeholder:

-                                    .having(
-                                      <<~SQL.squish
-                                        (
-                                          COALESCE(COUNT(DISTINCT photo_tags.photo_id), 0) * 1.0 / NULLIF(COUNT(DISTINCT photos.id), 0)
-                                        ) < #{tag_percentage_threshold}
-                                      SQL
-                                    )
+                                    .having(
+                                      'COALESCE(COUNT(DISTINCT photo_tags.photo_id), 0) * 1.0 / NULLIF(COUNT(DISTINCT photos.id), 0) < ?',
+                                      tag_percentage_threshold
+                                    )
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between daf8a0a and 1bcee4a.

📒 Files selected for processing (1)
  • app/models/photo_album.rb (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
  • GitHub Check: Lint
  • GitHub Check: Test
🔇 Additional comments (1)
app/models/photo_album.rb (1)

14-29: Implementation correctly addresses the PR objective.

The new threshold-based logic properly calculates the ratio of tagged photos to total photos per album. The combination of INNER JOIN (line 17) and LEFT JOIN (line 18) ensures that only albums with at least one photo are considered, and photos without tags are correctly included in the denominator. The NULLIF on line 23 provides good defensive programming against division by zero.

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.

SOG page photo album improvement

2 participants