refactor(sync): the empty-answer rule for a mirror is one function, vanished()
The YouTube playlist guard from the previous commit put sync/playlists.py over its size ceiling; the rule now lives beside should_prune as vanished(existing, listed), which the mirror calls in place of its own list. The pyright baseline also drops by one (187), from the plex/overlay split.
This commit is contained in:
@@ -22,7 +22,7 @@ from app import logs, progress, quota
|
||||
from app.auth import has_read_scope
|
||||
from app.models import Channel, Playlist, PlaylistItem, User, Video
|
||||
from app.sync.runner import token_users
|
||||
from app.sync.subscriptions import should_prune
|
||||
from app.sync.subscriptions import vanished
|
||||
from app.sync.videos import apply_video_details, parse_dt
|
||||
from app.youtube.client import YouTubeClient, YouTubeError
|
||||
|
||||
@@ -338,18 +338,10 @@ def pull_user_playlists(db: Session, user: User) -> dict:
|
||||
Playlist.source == "local",
|
||||
Playlist.yt_playlist_id.is_not(None),
|
||||
)
|
||||
)
|
||||
.scalars()
|
||||
.all()
|
||||
)
|
||||
# Drop mirrors whose YouTube playlist no longer exists — locked first, as every item write.
|
||||
# Never on an empty answer that contradicts the mirrors we hold: the same 200-with-no-items
|
||||
# blip `should_prune` guards the subscriptions against would drop every mirror (E32 S2).
|
||||
gone = (
|
||||
[pl for ytid, pl in existing.items() if ytid not in yt_ids]
|
||||
if should_prune(len(yt_ids), len(existing))
|
||||
else []
|
||||
).scalars()
|
||||
)
|
||||
# Drop vanished mirrors (none on an empty answer) — locked first, as every item write.
|
||||
gone = vanished(existing, yt_ids)
|
||||
if gone:
|
||||
lock_playlists(db, *(pl.id for pl in gone))
|
||||
for pl in gone:
|
||||
|
||||
Reference in New Issue
Block a user