fix(catalog): a follow from YouTube keeps an explored channel, and the list counts only what can come

A subscription pulled in from YouTube left an explored channel flagged as an exploration's, so its
later videos came in hidden from the Library with their watched marks waiting for good; a subscribe
landing while an exploration's videos came in left those flagged too. One step, settle_explored,
now holds the rule by who follows the channel now: the subscribe here, the subscription import, the
watched-channel videos and the explore page all end with it. Migration 0116 clears what the gap
left behind.

The list's "may still grow" count no longer counts a channel it already shows from a stub row, and
the comments on the cleanup's keep rule and on the in-memory daily shares say what they do.
This commit is contained in:
2026-10-24 11:29:14 +02:00
parent 33dd9ff054
commit bc8fe2cc6c
11 changed files with 242 additions and 20 deletions
+50
View File
@@ -0,0 +1,50 @@
"""Migration 0116's data step, DB-lane: an explored channel someone already follows becomes the
catalog's own, and no video stays flagged as an exploration's on a channel that is not one.
The schema half is checked by test_migrations.py; a flag left on is invisible there.
"""
from alembic import command
from alembic.config import Config
from sqlalchemy import text
from app.db import engine
def test_followed_explored_channels_and_their_videos_are_the_catalogs_own(db, make_user):
follower = make_user().id
cfg = Config("alembic.ini")
command.downgrade(cfg, "0115_takeout_channels")
try:
with engine.begin() as conn:
def channel(cid, explored):
conn.execute(
text("INSERT INTO channels (id, from_explore) VALUES (:c, :e)"),
{"c": cid, "e": explored},
)
conn.execute(
text(
"INSERT INTO videos (id, channel_id, published_at, via_explore)"
" VALUES (:v, :c, now(), true)"
),
{"v": f"v-{cid}", "c": cid},
)
channel("UCfollowed", True) # explored, then followed on youtube.com
channel("UCexplored", True) # explored, nobody follows it: stays the exploration's
channel("UCorganic", False) # a video flagged after a subscribe had cleared the channel
conn.execute(
text("INSERT INTO subscriptions (user_id, channel_id) VALUES (:u, 'UCfollowed')"),
{"u": follower},
)
finally:
command.upgrade(cfg, "head")
with engine.connect() as conn:
channels = dict(conn.execute(text("SELECT id, from_explore FROM channels")).tuples().all())
videos = dict(
conn.execute(text("SELECT channel_id, via_explore FROM videos")).tuples().all()
)
assert channels == {"UCfollowed": False, "UCexplored": True, "UCorganic": False}
assert videos == {"UCfollowed": False, "UCexplored": True, "UCorganic": False}