Fix track download count queries to exclude stem downloads#769
Merged
dylanjeffers merged 1 commit intomainfrom Apr 17, 2026
Merged
Fix track download count queries to exclude stem downloads#769dylanjeffers merged 1 commit intomainfrom
dylanjeffers merged 1 commit intomainfrom
Conversation
The per-track and per-user-total download count queries matched every track_downloads row by parent_track_id alone, so for an original track each stem download (which shares the same parent_track_id but has a different track_id) was counted as an additional download of the original. Require d.track_id = t.track_id in both queries so only the actual original-track download rows contribute to the count; stem tracks keep counting their own stem-specific rows as before. https://claude.ai/code/session_01M8ZDgw87vg9S2weug8Jj9P
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
This PR fixes the track download count queries to properly exclude stem track downloads from the count. Previously, the queries were incorrectly counting downloads of stem tracks as downloads of their parent tracks.
Key Changes
Query Logic Fix: Restructured the WHERE clause in
get_track_download_counts.sqlandget_user_track_download_count_total.sqlto add an explicitd.track_id = t.track_idcondition. This ensures that only downloads of the exact track (not stems of that track) are counted.parent_track_id = track_idparent_track_idmatches the stem's parent andtrack_idmatches the stem itselfTest Updates: Enhanced test cases in
v1_track_download_count_test.goto verify the fix:Implementation Details
The key fix moves the
d.track_id = t.track_idcondition outside the OR clause and into the main WHERE clause. This ensures that:stem_of IS NULL), we count downloads where the download'sparent_track_idequals the track'strack_idstem_of IS NOT NULL), we count downloads where the download'sparent_track_idmatches the stem's parent AND the download'strack_idmatches the stem'strack_idThis prevents stem track downloads from being incorrectly attributed to their parent tracks.
https://claude.ai/code/session_01M8ZDgw87vg9S2weug8Jj9P