summaryrefslogtreecommitdiff
path: root/Biz/PodcastItLater/Core.py
diff options
context:
space:
mode:
Diffstat (limited to 'Biz/PodcastItLater/Core.py')
-rw-r--r--Biz/PodcastItLater/Core.py14
1 files changed, 10 insertions, 4 deletions
diff --git a/Biz/PodcastItLater/Core.py b/Biz/PodcastItLater/Core.py
index f1f89e9..8d31956 100644
--- a/Biz/PodcastItLater/Core.py
+++ b/Biz/PodcastItLater/Core.py
@@ -1382,18 +1382,24 @@ class Database: # noqa: PLR0904
) -> dict[str, int]:
"""Get usage stats for user in period.
+ Counts episodes added to user's feed (via user_episodes table)
+ during the billing period, regardless of who created them.
+
Returns:
dict with keys: articles (int), minutes (int)
"""
with Database.get_connection() as conn:
cursor = conn.cursor()
- # Count articles created in period
+ # Count articles added to user's feed in period
+ # Uses user_episodes junction table to track when episodes
+ # were added, which correctly handles shared/existing episodes
cursor.execute(
"""
- SELECT COUNT(*) as count, SUM(duration) as total_seconds
- FROM episodes
- WHERE user_id = ? AND created_at >= ? AND created_at < ?
+ SELECT COUNT(*) as count, SUM(e.duration) as total_seconds
+ FROM user_episodes ue
+ JOIN episodes e ON e.id = ue.episode_id
+ WHERE ue.user_id = ? AND ue.added_at >= ? AND ue.added_at < ?
""",
(user_id, period_start.isoformat(), period_end.isoformat()),
)