perf(media): хелпер путей медиа-кеша + in-memory MIME-кеш на горячем пути /media
Docker Image CI / build (pull_request) Waiting to run
Docker Image CI / build (pull_request) Waiting to run
Задание 15: MEDIA_CACHE_DIR (резолвится один раз при импорте) + media_cache_path(
channel, post_id, fid=None) -> <root>/<channel>/<post_id>[/<fid>] как единый
источник истины формата пути. Заменены все ручные сборки os.path.abspath('./data/
cache')+join (7 мест); строки путей дословно идентичны (drop-in). remove_old_
cached_files_sync/download_new_files сохраняют параметр cache_dir (тестируемость).
Задание 16: in-memory _mime_types (bound _MIME_CACHE_MAX=50000, clear() при
переполнении) перед SQLite в prepare_file_response. Порядок: dict -> SQLite ->
python-magic; SQLite-хит и magic-детект наполняют dict. MIME по file_unique_id
иммутабелен -> повторный /media-хит не открывает SQLite-соединение (ни на чтение
MIME, ни на запись access-time — она уже в аккумуляторе). Кэшируются только
реальные типы.
closes #26
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -22,3 +22,20 @@ sys.modules['config'] = _mock_config
|
||||
# without this pin RSS <pubDate> values drift between machines (this sandbox is MSK).
|
||||
os.environ['TZ'] = 'UTC'
|
||||
time.tzset()
|
||||
|
||||
import pytest
|
||||
|
||||
|
||||
@pytest.fixture(autouse=True)
|
||||
def _reset_media_mime_cache():
|
||||
"""Clear the process-lifetime MIME dict before each test (issue #26).
|
||||
|
||||
``api_server._mime_types`` persists for the whole process, so an entry populated by one
|
||||
test would otherwise leak into another and mask a get/magic call the next test asserts on.
|
||||
"""
|
||||
try:
|
||||
import api_server
|
||||
api_server._mime_types.clear()
|
||||
except Exception:
|
||||
pass
|
||||
yield
|
||||
|
||||
Reference in New Issue
Block a user