Skip to content

Fix track download count queries to exclude stem downloads#769

Merged
dylanjeffers merged 1 commit intomainfrom
claude/fix-download-count-stems-vavrW
Apr 17, 2026
Merged

Fix track download count queries to exclude stem downloads#769
dylanjeffers merged 1 commit intomainfrom
claude/fix-download-count-stems-vavrW

Conversation

@dylanjeffers
Copy link
Copy Markdown
Contributor

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.sql and get_user_track_download_count_total.sql to add an explicit d.track_id = t.track_id condition. This ensures that only downloads of the exact track (not stems of that track) are counted.

    • For original tracks: downloads where parent_track_id = track_id
    • For stem tracks: downloads where parent_track_id matches the stem's parent and track_id matches the stem itself
  • Test Updates: Enhanced test cases in v1_track_download_count_test.go to verify the fix:

    • Added stem download rows to test data to ensure they are properly excluded from counts
    • Updated test comments to clarify the expected behavior
    • Reformatted INSERT statements for better readability

Implementation Details

The key fix moves the d.track_id = t.track_id condition outside the OR clause and into the main WHERE clause. This ensures that:

  1. For original tracks (where stem_of IS NULL), we count downloads where the download's parent_track_id equals the track's track_id
  2. For stem tracks (where stem_of IS NOT NULL), we count downloads where the download's parent_track_id matches the stem's parent AND the download's track_id matches the stem's track_id

This prevents stem track downloads from being incorrectly attributed to their parent tracks.

https://claude.ai/code/session_01M8ZDgw87vg9S2weug8Jj9P

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
@dylanjeffers dylanjeffers merged commit ee4ddad into main Apr 17, 2026
5 checks passed
@dylanjeffers dylanjeffers deleted the claude/fix-download-count-stems-vavrW branch April 17, 2026 18:05
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