mirror of
https://github.com/lrnselfreliance/wrolpi.git
synced 2026-11-29 11:26:25 -05:00
Fix file view tracking: docs mark viewed, previews count one view (#786)
Opening a doc on its page never set FileGroup.viewed, so docs were missing from Recently Viewed. GET /api/docs/:id now marks the doc viewed, with the same skip_viewed parameter as archives and videos. The file preview marked a file viewed more than once: opening from a ?preview= URL sent two tracked requests, and every tag change re-fetched the file with tracking on. The fetches now skip tracking, and the preview marks each opening viewed once. Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
a1292005ce
commit
531721c157
5 changed files with 114 additions and 5 deletions
|
|
@ -54,6 +54,24 @@ async def test_get_doc(async_client, test_session, test_directory, example_epub,
|
|||
assert response.json['file_group']
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_get_doc_marks_viewed(async_client, test_session, doc_factory):
|
||||
"""Getting a doc marks it viewed, unless skip_viewed is requested."""
|
||||
doc = doc_factory()
|
||||
file_group_id = doc.file_group_id
|
||||
test_session.commit()
|
||||
|
||||
request, response = await async_client.get(f'/api/docs/{file_group_id}?skip_viewed=true')
|
||||
assert response.status_code == HTTPStatus.OK
|
||||
test_session.expire_all()
|
||||
assert test_session.query(Doc).filter_by(file_group_id=file_group_id).one().file_group.viewed is None
|
||||
|
||||
request, response = await async_client.get(f'/api/docs/{file_group_id}')
|
||||
assert response.status_code == HTTPStatus.OK
|
||||
test_session.expire_all()
|
||||
assert test_session.query(Doc).filter_by(file_group_id=file_group_id).one().file_group.viewed is not None
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_docs_search_by_tag(async_client, test_session, doc_factory, tag_factory):
|
||||
"""Docs can be searched by tag."""
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue