Commit ee4ddad
Fix track download count queries to exclude stem downloads (#769)
## 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
Co-authored-by: Claude <noreply@anthropic.com>1 parent 92aa8c4 commit ee4ddad
File tree
5 files changed
+38
-18
lines changed- api
- dbv1
- queries
5 files changed
+38
-18
lines changedSome generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
7 | | - | |
8 | | - | |
9 | | - | |
10 | | - | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
11 | 14 | | |
12 | 15 | | |
13 | 16 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
9 | 9 | | |
10 | 10 | | |
11 | 11 | | |
| 12 | + | |
12 | 13 | | |
13 | 14 | | |
14 | 15 | | |
15 | | - | |
16 | | - | |
| 16 | + | |
17 | 17 | | |
18 | 18 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
17 | 17 | | |
18 | 18 | | |
19 | 19 | | |
20 | | - | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
21 | 23 | | |
22 | 24 | | |
23 | | - | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
24 | 30 | | |
25 | 31 | | |
26 | 32 | | |
| |||
37 | 43 | | |
38 | 44 | | |
39 | 45 | | |
40 | | - | |
| 46 | + | |
| 47 | + | |
41 | 48 | | |
42 | 49 | | |
43 | | - | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
44 | 54 | | |
45 | 55 | | |
46 | 56 | | |
| |||
64 | 74 | | |
65 | 75 | | |
66 | 76 | | |
67 | | - | |
| 77 | + | |
| 78 | + | |
68 | 79 | | |
69 | 80 | | |
70 | | - | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
71 | 85 | | |
72 | 86 | | |
73 | 87 | | |
| |||
0 commit comments