fix(stats): the full-history ratio counts the requested channels on both sides

"Full history: done / requested" counted every subscribed channel whose
back-catalog was complete in the numerator - also the ones another user asked
for, or short enough to finish on their own - against only the channels this
user requested, so the Stats page read "342/329". The numerator now counts the
requested channels that are done; "channels without full history yet" still
counts every subscribed one.
This commit is contained in:
2026-09-29 22:46:04 +02:00
parent aac79ffa53
commit a39504e617
2 changed files with 40 additions and 3 deletions
+7 -3
View File
@@ -71,7 +71,7 @@ def sync_status(user: User = Depends(current_user), db: Session = Depends(get_db
def my_status(user: User = Depends(current_user), db: Session = Depends(get_db)) -> dict: def my_status(user: User = Depends(current_user), db: Session = Depends(get_db)) -> dict:
"""Per-user sync progress: how far the channels *this* user subscribes to have synced.""" """Per-user sync progress: how far the channels *this* user subscribes to have synced."""
sub_join = and_(Subscription.channel_id == Channel.id, Subscription.user_id == user.id) sub_join = and_(Subscription.channel_id == Channel.id, Subscription.user_id == user.id)
total, details_synced, recent_synced, deep_done = db.execute( total, details_synced, recent_synced, all_deep_done = db.execute(
select( select(
func.count(Channel.id), func.count(Channel.id),
func.count(Channel.details_synced_at), func.count(Channel.details_synced_at),
@@ -82,7 +82,7 @@ def my_status(user: User = Depends(current_user), db: Session = Depends(get_db))
.join(Subscription, sub_join) .join(Subscription, sub_join)
).one() ).one()
total = total or 0 total = total or 0
deep_done = int(deep_done or 0) all_deep_done = int(all_deep_done or 0)
# Per-user full-history (deep) backfill: channels this user has opted in, and an ETA # Per-user full-history (deep) backfill: channels this user has opted in, and an ETA
# for the still-pending ones (quota-bound estimate). # for the still-pending ones (quota-bound estimate).
@@ -97,6 +97,10 @@ def my_status(user: User = Depends(current_user), db: Session = Depends(get_db))
.all() .all()
) )
deep_eta = estimate_deep_backfill(db, deep_requested_channels) deep_eta = estimate_deep_backfill(db, deep_requested_channels)
# "done / requested" is shown as one ratio, so both halves count the SAME channels: the ones this
# user asked full history for. Counting every subscribed channel whose back-catalog happens to be
# complete (another user asked, or it was short) gave "342/329".
deep_done = sum(1 for c in deep_requested_channels if c.backfill_done)
my_videos = db.scalar( my_videos = db.scalar(
select(func.count(Video.id)).join( select(func.count(Video.id)).join(
@@ -117,7 +121,7 @@ def my_status(user: User = Depends(current_user), db: Session = Depends(get_db))
"channels_recent_synced": recent_synced, "channels_recent_synced": recent_synced,
"channels_deep_done": deep_done, "channels_deep_done": deep_done,
"channels_recent_pending": total - recent_synced, "channels_recent_pending": total - recent_synced,
"channels_deep_pending": total - deep_done, "channels_deep_pending": total - all_deep_done,
"channels_deep_requested": len(deep_requested_channels), "channels_deep_requested": len(deep_requested_channels),
"deep_pending_count": deep_eta["channels_pending"], "deep_pending_count": deep_eta["channels_pending"],
"deep_eta_seconds": deep_eta["eta_seconds"], "deep_eta_seconds": deep_eta["eta_seconds"],
+33
View File
@@ -0,0 +1,33 @@
"""The Stats page's "Full history: done / requested" ratio counts the SAME channels on both sides — the
ones this user asked full history for. The numerator used to count every subscribed channel whose
back-catalog was complete (another user had asked, or the channel was short), so the page read
"342/329". "Channels without full history yet" still counts every subscribed channel. Needs the DB."""
from app.models import Channel, Subscription
def test_full_history_ratio_counts_only_the_requested_channels(db, make_user, as_user):
user = make_user("deep@example.com")
db.add_all(
[
Channel(id="UCreqdone", title="Requested, done", backfill_done=True),
Channel(id="UCreqopen", title="Requested, pending", backfill_done=False),
Channel(id="UCdone", title="Not requested, done anyway", backfill_done=True),
Channel(id="UCopen", title="Not requested, pending", backfill_done=False),
]
)
db.flush()
db.add_all(
[
Subscription(user_id=user.id, channel_id="UCreqdone", deep_requested=True),
Subscription(user_id=user.id, channel_id="UCreqopen", deep_requested=True),
Subscription(user_id=user.id, channel_id="UCdone"),
Subscription(user_id=user.id, channel_id="UCopen"),
]
)
db.commit()
body = as_user(user).get("/api/sync/my-status").json()
assert body["channels_deep_requested"] == 2
assert body["channels_deep_done"] == 1 # never more than it is out of
assert body["channels_deep_pending"] == 2 # subscribed channels without full history yet