Logging how long file searches take.

This commit is contained in:
Roland 2024-06-17 17:38:51 -06:00
parent 30a3ef1cac
commit 2d4fe7c70a
No known key found for this signature in database
GPG key ID: 9D6DBD3ACF11AB93
3 changed files with 10 additions and 9 deletions

View file

@ -1355,7 +1355,7 @@ def chunks_by_stem(it: List[Union[pathlib.Path, str, int]], size: int) -> Genera
@contextlib.contextmanager
def timer(name, level: str = 'debug'):
def timer(name, level: str = 'debug', logger__: logging.Logger = logger_):
"""Prints out the time elapsed during the call of some block.
Example:
@ -1364,7 +1364,7 @@ def timer(name, level: str = 'debug'):
"""
before = datetime.now()
log_method = getattr(logger_, level)
log_method = getattr(logger__, level)
try:
yield
finally:

View file

@ -8,7 +8,7 @@ from sanic_ext import validate
from sanic_ext.extensions.openapi import openapi
from wrolpi.common import get_media_directory, wrol_mode_check, get_relative_to_media_directory, logger, \
background_task, walk
background_task, walk, timer
from wrolpi.errors import InvalidFile, UnknownDirectory, FileUploadFailed, FileConflict
from . import lib, schema
from ..api_utils import json_response, api_app
@ -98,8 +98,9 @@ async def refresh_progress(request: Request):
)
@validate(schema.FilesSearchRequest)
async def post_search_files(_: Request, body: schema.FilesSearchRequest):
file_groups, total = lib.search_files(body.search_str, body.limit, body.offset, body.mimetypes, body.model,
body.tag_names, body.headline, body.months, body.from_year, body.to_year)
with timer('Searching all files', 'info', logger__=logger):
file_groups, total = lib.search_files(body.search_str, body.limit, body.offset, body.mimetypes, body.model,
body.tag_names, body.headline, body.months, body.from_year, body.to_year)
return json_response(dict(file_groups=file_groups, totals=dict(file_groups=total)))

View file

@ -383,15 +383,15 @@ async def test_refresh_a_text_no_indexer(test_async_client, test_session, make_f
@pytest.mark.asyncio
async def test_refresh_many_files(test_async_client, test_session, make_files_structure):
"""Used to profile file refreshing"""
count = 10_000
make_files_structure([f'{uuid4()}.txt' for _ in range(count)])
file_count = 10_000
make_files_structure([f'{uuid4()}.txt' for _ in range(file_count)])
with timer('first refresh'):
await lib.refresh_files()
assert test_session.query(FileGroup).count() == count
assert test_session.query(FileGroup).count() == file_count
with timer('second refresh'):
await lib.refresh_files()
assert test_session.query(FileGroup).count() == count
assert test_session.query(FileGroup).count() == file_count
@pytest.mark.asyncio