mirror of
https://github.com/lrnselfreliance/wrolpi.git
synced 2026-11-26 09:56:17 -05:00
Fixing issue where not all commonly shared tags were found during bulk tagging.
This commit is contained in:
parent
edf0db8f7f
commit
5fd202fabe
3 changed files with 50 additions and 5 deletions
|
|
@ -185,7 +185,7 @@ export function BulkTagModal({open, onClose, paths, onComplete}) {
|
|||
indicating
|
||||
color="blue"
|
||||
>
|
||||
{progress.completed} / {progress.total} files
|
||||
<span {...t}>{progress.completed} / {progress.total} files</span>
|
||||
</Progress>
|
||||
{progress.queued_jobs > 0 && (
|
||||
<p {...t}>{progress.queued_jobs} job{progress.queued_jobs !== 1 ? 's' : ''} queued</p>
|
||||
|
|
|
|||
|
|
@ -1706,9 +1706,13 @@ def get_bulk_tag_preview(paths: List[str]) -> BulkTagPreview:
|
|||
|
||||
# Find tags shared by ALL files
|
||||
# First, get all FileGroups and their tags
|
||||
# We query by stem prefix because unique_files may contain non-primary files
|
||||
# (e.g., .readability.json) but FileGroups are stored with primary_path (e.g., .html)
|
||||
with get_db_session() as session:
|
||||
from sqlalchemy import or_
|
||||
stems = [split_path_stem_and_suffix(f, full=True)[0] for f in unique_files]
|
||||
file_groups = session.query(FileGroup).filter(
|
||||
FileGroup.primary_path.in_([str(f) for f in unique_files])
|
||||
or_(*[FileGroup.primary_path.like(f'{stem}%') for stem in stems])
|
||||
).all()
|
||||
|
||||
if not file_groups:
|
||||
|
|
@ -1782,10 +1786,16 @@ def queue_bulk_tag_job(paths: List[str], add_tag_names: List[str], remove_tag_na
|
|||
)
|
||||
api_app.shared_ctx.bulk_tag_queue.put(job)
|
||||
|
||||
# Update queued jobs count
|
||||
# Reset progress state and update queued jobs count
|
||||
try:
|
||||
current_queued = api_app.shared_ctx.bulk_tag.get('queued_jobs', 0)
|
||||
api_app.shared_ctx.bulk_tag['queued_jobs'] = current_queued + 1
|
||||
api_app.shared_ctx.bulk_tag.update(dict(
|
||||
status='idle',
|
||||
total=0,
|
||||
completed=0,
|
||||
error=None,
|
||||
queued_jobs=current_queued + 1,
|
||||
))
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
|
|
|
|||
|
|
@ -1206,7 +1206,8 @@ async def test_get_bulk_tag_preview_files(async_client, test_session, make_files
|
|||
assert 'only_foo' not in preview.shared_tag_names # Not shared by all
|
||||
|
||||
|
||||
def test_get_bulk_tag_preview_directory(test_session, make_files_structure, test_directory):
|
||||
@pytest.mark.asyncio
|
||||
async def test_get_bulk_tag_preview_directory(test_session, make_files_structure, test_directory, tag_factory):
|
||||
"""get_bulk_tag_preview recursively finds files in directories."""
|
||||
make_files_structure({
|
||||
'mydir/foo.txt': 'foo',
|
||||
|
|
@ -1219,6 +1220,40 @@ def test_get_bulk_tag_preview_directory(test_session, make_files_structure, test
|
|||
assert preview.file_count == 3
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_get_bulk_tag_preview_multi_file_filegroup(async_client, test_session, make_files_structure,
|
||||
test_directory, tag_factory):
|
||||
"""get_bulk_tag_preview finds shared tags for multi-file FileGroups.
|
||||
|
||||
This tests a bug where `get_unique_files_by_stem` may return a non-primary file (e.g. .readability.json)
|
||||
but the FileGroup query looks for exact primary_path match (e.g. .html), causing no FileGroup to be found.
|
||||
"""
|
||||
# Create a multi-file FileGroup like an Archive (primary is .html, but has .readability.json, etc.)
|
||||
# SingleFile archives are named with the pattern: %Y-%m-%d-%H-%M-%S_title.html
|
||||
html_file, json_file, txt_file = make_files_structure({
|
||||
'archive/2025-01-01-12-00-00_Page Title.html': '<html>content</html>',
|
||||
'archive/2025-01-01-12-00-00_Page Title.readability.json': '{"title": "Page"}',
|
||||
'archive/2025-01-01-12-00-00_Page Title.readability.txt': 'Page content',
|
||||
})
|
||||
|
||||
# Create the FileGroup with .html as the primary path
|
||||
fg = FileGroup.from_paths(test_session, html_file, json_file, txt_file)
|
||||
test_session.commit()
|
||||
|
||||
# Verify the primary_path is the .html file
|
||||
assert fg.primary_path.suffix == '.html', f'Expected primary_path to be .html, got {fg.primary_path}'
|
||||
|
||||
# Add a tag to this FileGroup
|
||||
tag = await tag_factory('my_tag')
|
||||
fg.add_tag(tag.id)
|
||||
test_session.commit()
|
||||
|
||||
# Preview for the directory should find the FileGroup and its tag
|
||||
preview = lib.get_bulk_tag_preview(['archive/'])
|
||||
assert preview.file_count == 1, f'Expected 1 FileGroup, got {preview.file_count}'
|
||||
assert 'my_tag' in preview.shared_tag_names, f'Expected my_tag in shared tags, got {preview.shared_tag_names}'
|
||||
|
||||
|
||||
def test_get_bulk_tag_preview_empty(test_session, test_directory):
|
||||
"""get_bulk_tag_preview returns 0 for empty or non-existent paths."""
|
||||
preview = lib.get_bulk_tag_preview([])
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue