Archive and doc pages record a view in its own write transaction

Viewing an archive or a doc marked it viewed on the request's read transaction. SQLite cannot
upgrade a read to a writer once another connection has committed (during a download or refresh),
and it does not wait on busy_timeout for that. The archive page returned a 500; the doc page
returned 200 but its view was lost when the request's commit failed.

Build the response on the read, then record the view in `request.ctx.db.write()`, as the video
page already does.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Roland 2026-10-11 12:43:16 -06:00
parent 4202e6a7e5
commit ce88771ab8
No known key found for this signature in database
GPG key ID: 1BA620CE6C9A4680
4 changed files with 78 additions and 3 deletions

View file

@ -31,8 +31,13 @@ async def statistics(request: Request):
async def get_doc(request: Request, file_group_id: int):
session = request.ctx.session
skip_viewed = request.args.get('skip_viewed', '').lower() == 'true'
doc = _get_doc(session, file_group_id, skip_viewed=skip_viewed)
return json_response(_doc_response(doc))
doc = _get_doc(session, file_group_id, skip_viewed=True)
response = _doc_response(doc)
if not skip_viewed:
# Marking the doc viewed is a write; it must not upgrade the read above (see `RequestDB.write`).
with request.ctx.db.write():
response['file_group']['viewed'] = doc.file_group.set_viewed()
return json_response(response)
doc_limit_limiter = api_param_limiter(100)