fix: review round 2 — Clear watch progress clears only the resume point, big view focus by the way it arrived, dialog name, reason tooltip, backfill locks
This commit is contained in:
@@ -89,14 +89,17 @@ def _retitle(db: Session, a: MediaAsset, adapter: adapters.SourceAdapter, url: s
|
||||
named = normalize_title(adapter.title(info))
|
||||
if not named or adapter.is_placeholder_title(named):
|
||||
return False
|
||||
# One conditional write, not a read and a compare: a name its owner gives while this runs (the
|
||||
# poster step can take seconds before the commit) is not overwritten by what was read before it.
|
||||
# One conditional write, not a read and a compare: a name its owner gives while the page is read
|
||||
# is not overwritten by what was read before it. The asset first, as every other writer of the
|
||||
# two locks them (`service.lock_own_job`): the session does not flush by itself.
|
||||
placeholder = a.title
|
||||
a.title = named
|
||||
db.flush()
|
||||
db.execute(
|
||||
update(DownloadJob)
|
||||
.where(DownloadJob.asset_id == a.id, DownloadJob.display_name == a.title)
|
||||
.where(DownloadJob.asset_id == a.id, DownloadJob.display_name == placeholder)
|
||||
.values(display_name=named[:DISPLAY_TEXT_MAX])
|
||||
)
|
||||
a.title = named
|
||||
return True
|
||||
|
||||
|
||||
@@ -127,6 +130,9 @@ def run() -> dict:
|
||||
if adapter.wants_metadata_backfill():
|
||||
url = a.source_webpage_url or service.source_url(a.source_kind, a.source_ref)
|
||||
if _retitle(db, a, adapter, url):
|
||||
# Before the poster step: it can cut a frame for 30 s, and these locks held
|
||||
# across it block a rename and deadlock a delete.
|
||||
db.commit()
|
||||
retitled += 1
|
||||
log.info("asset %s retitled", a.id) # the title names what they downloaded
|
||||
if a.poster_path is None:
|
||||
|
||||
@@ -255,17 +255,6 @@ def mark(db: Session, user: User, video_id: str, status: str) -> None:
|
||||
)
|
||||
|
||||
|
||||
def clear_state(db: Session, user: User, video_id: str) -> None:
|
||||
"""The video back to pristine for this user: status, resume point and `watched_at` all go.
|
||||
Playlist membership lives elsewhere and stays."""
|
||||
lock_takeout(db, user) # as `unmark`
|
||||
row = queries.video_state(db, user, video_id)
|
||||
if row is not None:
|
||||
db.delete(row)
|
||||
_remember_unmark(db, user, video_id)
|
||||
db.flush()
|
||||
|
||||
|
||||
def set_progress(db: Session, user: User, video_id: str, position: int) -> None:
|
||||
"""The player's resume point. 0 clears it: a row holding nothing else goes, one with a status
|
||||
(watched, hidden) keeps it with the position zeroed. The status itself is never changed here.
|
||||
|
||||
@@ -204,22 +204,21 @@ def set_video_state(
|
||||
return {"ok": True, "video_id": video_id, "status": status}
|
||||
|
||||
|
||||
@router.delete("/videos/{video_id}/state")
|
||||
def clear_video_state(
|
||||
@router.delete("/videos/{video_id}/progress")
|
||||
def clear_video_progress(
|
||||
video_id: str,
|
||||
user: User = Depends(current_user),
|
||||
db: Session = Depends(get_db),
|
||||
) -> dict:
|
||||
"""Reset a video to pristine for this user — drop the whole VideoState row (status,
|
||||
watch position and watched_at), as if it had never been opened. Saved/playlist membership
|
||||
lives elsewhere and is untouched."""
|
||||
"""Forget where the user left a video: its resume point goes, its status (watched, hidden) stays.
|
||||
Saved/playlist membership lives elsewhere and is untouched."""
|
||||
try:
|
||||
service.clear_state(db, user, video_id)
|
||||
service.set_progress(db, user, video_id, 0)
|
||||
db.commit()
|
||||
# silent-ok: the row went under the delete, which is the outcome the delete wanted.
|
||||
# silent-ok: the row went under the write, which is the outcome the write wanted.
|
||||
except StaleDataError:
|
||||
db.rollback()
|
||||
return {"ok": True, "video_id": video_id, "status": "new", "position_seconds": 0}
|
||||
return {"ok": True, "video_id": video_id, "position_seconds": 0}
|
||||
|
||||
|
||||
@router.post("/videos/{video_id}/progress")
|
||||
|
||||
Reference in New Issue
Block a user