fix(search): every related and live-search request takes a slot, and a failed one gives it back
A related list's cursor cost nothing, and a cursor is a free string: a replayed one read and enriched without end. Every request now takes a slot of the user's daily cap — taken under a lock before the work (`quota.claim_action`), so requests sent together cannot all pass the last free one, and given back when the request fails outright (`quota.refund_action`). The live search's scrape source takes its slots the same way. A limit of 0 turns the feature off: a distinct 409 `related_disabled` / `search_disabled`, and `/api/me` says `related_enabled` / `search_enabled` so the UI can leave it out. A videos.list that fails no longer reads as an empty page: `ingest_candidates` raises, and the search and the related list answer the refusal (the shared budget spent says "quota") instead of "no results". The two routes' page loops are one (`_gather`). `clear` deletes only what the caller found: a related list's rows carry no find, and any user could name them.
This commit is contained in:
@@ -291,6 +291,23 @@ def test_search_results_cleared_through_the_route_are_gone(db, make_user, as_use
|
||||
assert db.execute(select(SearchFind)).first() is None
|
||||
|
||||
|
||||
def test_clearing_leaves_a_video_the_caller_never_found(db, make_user, as_user):
|
||||
# A related list ingests its rows with no find: they are in someone's list right now, and an id
|
||||
# any user could name must not delete them from under it.
|
||||
user = make_user()
|
||||
_video(db, "s1", via_search=True)
|
||||
_video(db, "s2", via_search=True)
|
||||
db.add(SearchFind(user_id=user.id, video_id="s1"))
|
||||
db.commit()
|
||||
r = as_user(user).post("/api/search/clear", json={"video_ids": ["s1", "s2"]})
|
||||
assert r.json() == {"ok": True, "removed": 1}
|
||||
db.expire_all()
|
||||
assert db.get(Video, "s1") is None and db.get(Video, "s2") is not None
|
||||
# Naming only ids it never found removes nothing.
|
||||
r = as_user(user).post("/api/search/clear", json={"video_ids": ["s2"]})
|
||||
assert r.json() == {"ok": True, "removed": 0}
|
||||
|
||||
|
||||
# --- Plex show and season marks ---------------------------------------------------------------
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user