Adding toggle to disable the tags directory feature.

This commit is contained in:
Roland 2026-01-31 12:54:27 -07:00
parent 74cb5171da
commit 9005c0deff
No known key found for this signature in database
GPG key ID: 1BA620CE6C9A4680
14 changed files with 141 additions and 21 deletions

View file

@ -2,7 +2,7 @@ import asyncio
import json
import pathlib
from abc import ABC
from typing import List, Tuple, Iterable
from typing import Callable, List, Tuple, Iterable
from sqlalchemy import not_
from sqlalchemy.orm import Session
@ -260,10 +260,11 @@ def model_archive(session: Session, file_group: FileGroup) -> Archive:
@register_modeler
async def archive_modeler():
async def archive_modeler(progress_callback: Callable[[int], None] = None):
"""Searches DB for FileGroups that contain an HTML file. If the HTML file is a SingleFile, we model it as an
Archive."""
invalid_archives = set()
total_processed = 0
while True:
with get_db_session(commit=True) as session:
@ -276,9 +277,10 @@ async def archive_modeler():
.outerjoin(Archive, Archive.file_group_id == FileGroup.id) \
.limit(20)
results: Iterable[Tuple[FileGroup, Archive]]
results_list = list(results)
processed = 0
for processed, (file_group, archive) in enumerate(results):
for processed, (file_group, archive) in enumerate(results_list):
with slow_logger(1, f'Modeling archive took %(elapsed)s seconds: {file_group}',
logger__=logger):
if archive:
@ -309,6 +311,12 @@ async def archive_modeler():
session.commit()
# Report batch progress
batch_count = len(results_list)
total_processed += batch_count
if progress_callback and batch_count > 0:
progress_callback(total_processed)
if processed < 19:
# Did not reach limit (enumerate is 0-indexed, so 19 = 20 items), do not query again.
if __debug__ and logger.isEnabledFor(TRACE_LEVEL):

View file

@ -1,5 +1,5 @@
import asyncio
from typing import List, Tuple
from typing import Callable, List, Tuple
from sqlalchemy.orm import Session
@ -18,7 +18,8 @@ VIDEO_PROCESSING_LIMIT = 20
@register_modeler
async def video_modeler():
async def video_modeler(progress_callback: Callable[[int], None] = None):
total_processed = 0
while True:
with get_db_session(commit=True) as session:
file_groups = session.query(FileGroup, Video).filter(
@ -58,6 +59,11 @@ async def video_modeler():
session.commit()
# Report batch progress
total_processed += len(file_groups)
if progress_callback and len(file_groups) > 0:
progress_callback(total_processed)
if processed < VIDEO_PROCESSING_LIMIT:
# Did not reach limit, do not query again.
break

View file

@ -3,7 +3,7 @@ import functools
import pathlib
import re
from datetime import datetime
from typing import List, Tuple, Dict
from typing import Callable, List, Tuple, Dict
import cachetools.func
from libzim import Entry
@ -62,7 +62,8 @@ def model_zim(file_group: FileGroup, session: Session) -> Zim:
@register_modeler
async def zim_modeler():
async def zim_modeler(progress_callback: Callable[[int], None] = None):
total_processed = 0
while True:
with get_db_session(commit=True) as session:
file_groups = session.query(FileGroup, Zim) \
@ -95,6 +96,11 @@ async def zim_modeler():
logger.debug(f'Modeled {processed} zim files')
# Report batch progress
total_processed += len(file_groups)
if progress_callback and len(file_groups) > 0:
progress_callback(total_processed)
if processed < 10:
# Did not reach limit, do not query again.
break