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:
@@ -1,6 +1,6 @@
|
||||
"""Import the authenticated user's YouTube subscriptions and channel metadata."""
|
||||
|
||||
from collections.abc import Iterable
|
||||
from collections.abc import Collection, Iterable
|
||||
from datetime import datetime, timedelta, timezone
|
||||
|
||||
from sqlalchemy import or_, select
|
||||
@@ -119,6 +119,15 @@ def should_prune(fetched_count: int, existing_count: int) -> bool:
|
||||
return fetched_count > 0 or existing_count == 0
|
||||
|
||||
|
||||
def vanished[K, V](existing: dict[K, V], listed: Collection[K]) -> list[V]:
|
||||
"""The local mirrors whose key the remote listing no longer has — none at all when the listing
|
||||
is an empty answer that contradicts them (`should_prune`). The YouTube playlist mirrors use it:
|
||||
without it, one blip dropped every mirror (E32 S2)."""
|
||||
if not should_prune(len(listed), len(existing)):
|
||||
return []
|
||||
return [row for key, row in existing.items() if key not in listed]
|
||||
|
||||
|
||||
def import_subscriptions(db: Session, user: User) -> dict:
|
||||
"""Pull all subscriptions for `user`, upsert channels + subscription links, prune
|
||||
channels the user has unsubscribed from on YouTube, and fetch channel details for
|
||||
|
||||
Reference in New Issue
Block a user