mirror of
https://github.com/lrnselfreliance/wrolpi.git
synced 2026-11-26 01:46:18 -05:00
db: request-path library functions use the request's connection
Library functions an API request reaches now take the request's Session (first argument) instead of opening their own session or cursor, so a request needs one SQLite connection. Raw SQL runs through the new `wrolpi.db.session_curs(session)`, a cursor on the Session's connection; `RequestDB.curs()` uses it. - Search: files, videos, archives, flasher, and docs search share the request connection for the total, the page of ids, and the page's models (3 connections -> 1). - Zim search, including tag-filtered search and estimates (2 -> 1). - Channel detail (`Channel.get_statistics` reads on the Channel's own Session) and the channel list. - Video detail, edit, description, captions, comments and transcode. `get_video_for_app` and `update_video` no longer commit; their handlers use `request.ctx.db.write()`, so editing a Video and reading it back is one transaction. - Tags (list, overlaps, recent), file statistics and estimates, other estimates, bulk tag preview, the download list, retry, kill and the status summary, and docs/videos/archive statistics. Not converted: file operations that refresh files inside the request (delete, rename, upload, channel and collection tag/move) commit page by page in code shared with the file worker; the cached zim entry lookup; config import. The connection-count tests now assert one connection for every endpoint they cover (no xfails left), and cover the videos and archive statistics endpoints, which had no API test. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
a2bef48c6c
commit
24c5796fc6
34 changed files with 545 additions and 422 deletions
|
|
@ -293,10 +293,10 @@ async def test_search_docs_attaches_section_hint_epub(test_session, test_directo
|
|||
])
|
||||
|
||||
# "mullen" is only in the document body (d_text), so a deep search is required to match it.
|
||||
results, total = _search_docs(search_str='mullen', mimetype='application/epub')
|
||||
results, total = _search_docs(test_session, search_str='mullen', mimetype='application/epub')
|
||||
assert total == 0, 'Document contents are not searched unless deep=True'
|
||||
|
||||
results, total = _search_docs(search_str='mullen', mimetype='application/epub', deep=True)
|
||||
results, total = _search_docs(test_session, search_str='mullen', mimetype='application/epub', deep=True)
|
||||
assert total == 1
|
||||
assert results[0]['id'] == fg.id
|
||||
hint = results[0]['section_hint']
|
||||
|
|
@ -318,7 +318,7 @@ async def test_search_docs_attaches_section_hint_pdf(test_session, test_director
|
|||
(3, 'Page 3', 'here is where mullen shows up'),
|
||||
])
|
||||
|
||||
results, total = _search_docs(search_str='mullen', mimetype='application/pdf', deep=True)
|
||||
results, total = _search_docs(test_session, search_str='mullen', mimetype='application/pdf', deep=True)
|
||||
assert total == 1
|
||||
assert results[0]['id'] == fg.id
|
||||
hint = results[0]['section_hint']
|
||||
|
|
@ -334,7 +334,7 @@ async def test_search_docs_no_hint_when_no_query(test_session, test_directory):
|
|||
'gamma.pdf', 'application/pdf', [
|
||||
(1, 'Page 1', 'whatever'),
|
||||
])
|
||||
results, _ = _search_docs(mimetype='application/pdf')
|
||||
results, _ = _search_docs(test_session, mimetype='application/pdf')
|
||||
assert results and results[0]['id'] == fg.id
|
||||
assert 'section_hint' not in results[0]
|
||||
|
||||
|
|
@ -360,15 +360,15 @@ async def test_search_docs_browse_walks_file_group_date_index(test_session, test
|
|||
assert 'TEMP B-TREE' not in plan, plan
|
||||
|
||||
# Newest first, NULL published dates last, same as the filtered ORM path.
|
||||
results, total = _search_docs()
|
||||
results, total = _search_docs(test_session, )
|
||||
assert total == 3
|
||||
assert [i['id'] for i in results] == [docs[2].file_group_id, docs[1].file_group_id, docs[0].file_group_id]
|
||||
|
||||
# Paging still works on the fast path.
|
||||
results, total = _search_docs(limit=1, offset=1)
|
||||
results, total = _search_docs(test_session, limit=1, offset=1)
|
||||
assert total == 3
|
||||
assert [i['id'] for i in results] == [docs[1].file_group_id]
|
||||
|
||||
# Filtered searches are unaffected.
|
||||
results, total = _search_docs(mimetype='application/pdf')
|
||||
results, total = _search_docs(test_session, mimetype='application/pdf')
|
||||
assert total == 3
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue