diff --git a/README.md b/README.md index 9e0c6b0..14b9422 100644 --- a/README.md +++ b/README.md @@ -521,6 +521,8 @@ The plugin asks the Python service for the libraries visible to the configured J The plugin's library selection is authoritative. Saving the plugin settings posts the selected library IDs to Scene Search; any previously indexed Jellyfin library that is no longer selected is removed from canonical SQLite and Meilisearch. Nothing is removed merely because of a background Jellyfin poll. If a library has been deleted from Jellyfin, it disappears from the checkbox list and is removed the next time the plugin posts its selection. +Library removal is targeted. **Apply selection only** (or saving the plugin settings) deletes deselected libraries from SQLite and deletes only matching `jellyfin_library_id` documents from Meilisearch; it does not clear/re-feed the complete Meilisearch index. **Index selected libraries** remains the action for scanning media. If that scan finds all retained libraries unchanged, Scene Search now skips the final full Meilisearch rebuild as well. + Use **Apply library selection / index** to apply the same authoritative set and start a backend indexing job. An empty selection is allowed only after an explicit confirmation and removes all Jellyfin-backed Scene Search data. The plugin shows an overall percentage/progress bar across all selected libraries as well as the current library, item and frame progress, and polls until the job completes. When ingestion finishes, the backend automatically rebuilds Meilisearch, so newly indexed vectors are searchable without a separate `sync-meili` command. The same page also has **Start / resume captioning** and **Pause**. Pause finishes the currently active routing batch or Ollama frame request, then waits before starting the next unit; Resume continues the same in-memory job without rebuilding its queues. Every successful caption is committed immediately, so a process/container interruption can still be recovered by pressing Start / resume and continuing from uncaptained frames. **Force recaption existing frames** deliberately regenerates captions, but reuses saved routing decisions while the routing policy is still current. diff --git a/jellyfin-plugin/Jellyfin.Plugin.SceneSearch/Configuration/configPage.html b/jellyfin-plugin/Jellyfin.Plugin.SceneSearch/Configuration/configPage.html index aaed910..3af5afc 100644 --- a/jellyfin-plugin/Jellyfin.Plugin.SceneSearch/Configuration/configPage.html +++ b/jellyfin-plugin/Jellyfin.Plugin.SceneSearch/Configuration/configPage.html @@ -46,13 +46,16 @@

Indexed Libraries

- Choose which Jellyfin libraries Scene Search should keep indexed. Applying this selection removes deselected libraries from Scene Search SQLite and Meilisearch. Selection is stored in this plugin, not in the Python .env file. + Choose which Jellyfin libraries Scene Search should keep indexed. Apply selection only removes deselected libraries directly from Scene Search SQLite and Meilisearch without rebuilding the full Meilisearch index. Selection is stored in this plugin, not in the Python .env file.
Loading libraries…
+
-
Deselected libraries are removed from Scene Search SQLite and Meilisearch when you apply the selection.
+
Apply selection removes deselected libraries directly from SQLite and Meilisearch. It does not rebuild the whole search index.
Loading…
- + +
@@ -239,6 +240,37 @@ } } + async function applyLibrarySelection() { + const ids = selectedLibraries(); + if (!ids.length && !window.confirm( + 'No libraries are selected. This will remove all Jellyfin-backed Scene Search data from SQLite and Meilisearch. Continue?' + )) { + return; + } + + try { + $('indexStatus').className = 'status'; + $('indexStatus').textContent = 'Applying library selection...'; + const result = await api('/api/jellyfin/libraries/selection', { + method:'POST', + body:JSON.stringify({library_ids:ids, force:false}) + }); + const removedLibraries = Number(result.removed_libraries || 0); + const removedMedia = Number(result.removed_media || 0); + $('indexStatus').className = 'status ok'; + $('indexStatus').textContent = removedLibraries + ? 'Selection applied: removed ' + removedLibraries + ' librar' + + (removedLibraries === 1 ? 'y' : 'ies') + ' and ' + removedMedia + ' media items' + : 'Selection applied: nothing to remove'; + $('indexDetail').textContent = 'No full Meilisearch rebuild was run.'; + await loadLibraries(); + refreshHealth(); + } catch (e) { + $('indexStatus').className = 'status error'; + $('indexStatus').textContent = e.message; + } + } + async function startIndex() { const ids = selectedLibraries(); if (!ids.length && !window.confirm( @@ -436,6 +468,7 @@ }; $('refreshLibraries').onclick = loadLibraries; $('selectAll').onclick = () => document.querySelectorAll('.libraryCheck').forEach(x => x.checked = true); + $('applyLibraries').onclick = applyLibrarySelection; $('indexNow').onclick = startIndex; $('captionNow').onclick = startCaption; $('captionPause').onclick = toggleCaptionPause; diff --git a/tests/test_index_jobs.py b/tests/test_index_jobs.py index f22d406..828b6a5 100644 --- a/tests/test_index_jobs.py +++ b/tests/test_index_jobs.py @@ -1,7 +1,9 @@ from __future__ import annotations +import threading import unittest from types import SimpleNamespace +from unittest.mock import MagicMock, patch from scene_search.index_jobs import IndexJobManager @@ -52,6 +54,115 @@ class OverallIndexProgressTests(unittest.TestCase): self.assertEqual(status["overall_items_completed"], 10) self.assertEqual(status["overall_percent"], 99.0) + def test_library_only_removal_skips_full_meili_rebuild(self) -> None: + meili = MagicMock() + service = SimpleNamespace( + model_lock=threading.Lock(), + get_embedder=lambda: object(), + meili=meili, + ) + manager = IndexJobManager(service) # type: ignore[arg-type] + manager._state = { + "running": True, + "stage": "starting", + "library_item_totals": [2], + "overall_items_total": 2, + } + + with ( + patch( + "scene_search.index_jobs.reconcile_selected_libraries", + return_value={ + "removed_library_ids": ["lib-removed"], + "removed_libraries": 1, + "removed_media": 50, + }, + ), + patch( + "scene_search.index_jobs.index_libraries", + return_value=( + object(), + { + "library_total": 1, + "indexed": 0, + "skipped": 2, + "failed": 0, + "pruned": 0, + }, + ), + ), + patch("scene_search.index_jobs.build_jellyfin_client"), + patch("scene_search.index_jobs.rebuild_meili") as rebuild, + ): + manager._run( + [{"Id": "lib-keep", "Name": "Keep"}], + {"lib-keep"}, + False, + ) + + meili.delete_jellyfin_libraries.assert_called_once_with( + ["lib-removed"] + ) + rebuild.assert_not_called() + status = manager.status() + self.assertEqual(status["stage"], "complete") + self.assertFalse(status["full_meili_rebuild"]) + self.assertEqual(status["documents_processed"], 0) + self.assertEqual(status["pruned"], 50) + + def test_retained_library_change_still_rebuilds_meili(self) -> None: + service = SimpleNamespace( + model_lock=threading.Lock(), + get_embedder=lambda: object(), + meili=MagicMock(), + ) + manager = IndexJobManager(service) # type: ignore[arg-type] + manager._state = { + "running": True, + "stage": "starting", + "library_item_totals": [2], + "overall_items_total": 2, + } + + with ( + patch( + "scene_search.index_jobs.reconcile_selected_libraries", + return_value={ + "removed_library_ids": [], + "removed_libraries": 0, + "removed_media": 0, + }, + ), + patch( + "scene_search.index_jobs.index_libraries", + return_value=( + object(), + { + "library_total": 1, + "indexed": 1, + "skipped": 1, + "failed": 0, + "pruned": 0, + }, + ), + ), + patch("scene_search.index_jobs.build_jellyfin_client"), + patch( + "scene_search.index_jobs.rebuild_meili", + return_value=123, + ) as rebuild, + ): + manager._run( + [{"Id": "lib-keep", "Name": "Keep"}], + {"lib-keep"}, + False, + ) + + rebuild.assert_called_once() + status = manager.status() + self.assertTrue(status["full_meili_rebuild"]) + self.assertEqual(status["documents_processed"], 123) + def test_complete_is_one_hundred_percent(self) -> None: manager = self.make_manager() manager._state = {