refactor(autocomplete): remove old CSV fallback, use TagFTSIndex exclusively

Remove all autocomplete.txt parsing logic and fallback code, simplifying
the service to use only TagFTSIndex for Danbooru/e621 tag search
with category filtering.

- Remove WordEntry dataclass and _words_cache, _file_path attributes
- Remove _determine_file_path(), get_file_path(), load_words(), save_words(),
  get_content(), _parse_csv_content() methods
- Simplify search_words() to only use TagFTSIndex, always returning
  enriched results with {tag_name, category, post_count}
- Remove GET/POST /api/lm/custom-words endpoints (unused)
- Keep GET /api/lm/custom-words/search for frontend autocomplete
- Rewrite tests to focus on TagFTSIndex integration

This reduces code by 446 lines and removes untested pysssss plugin
integration. Feature is unreleased so no backward compatibility needed.
This commit is contained in:
Will Miao
2026-01-26 20:36:00 +08:00
parent 31d94d7ea2
commit 7249c9fd4b
4 changed files with 110 additions and 447 deletions

View File

@@ -1202,34 +1202,12 @@ class FileSystemHandler:
class CustomWordsHandler:
"""Handler for custom autocomplete words."""
"""Handler for autocomplete via TagFTSIndex."""
def __init__(self) -> None:
from ...services.custom_words_service import get_custom_words_service
self._service = get_custom_words_service()
async def get_custom_words(self, request: web.Request) -> web.Response:
"""Get the content of the custom words file."""
try:
content = self._service.get_content()
return web.Response(text=content, content_type="text/plain")
except Exception as exc:
logger.error("Error getting custom words: %s", exc, exc_info=True)
return web.json_response({"error": str(exc)}, status=500)
async def update_custom_words(self, request: web.Request) -> web.Response:
"""Update the custom words file content."""
try:
content = await request.text()
success = self._service.save_words(content)
if success:
return web.Response(status=200)
else:
return web.json_response({"error": "Failed to save custom words"}, status=500)
except Exception as exc:
logger.error("Error updating custom words: %s", exc, exc_info=True)
return web.json_response({"error": str(exc)}, status=500)
async def search_custom_words(self, request: web.Request) -> web.Response:
"""Search custom words with autocomplete.
@@ -1563,8 +1541,6 @@ class MiscHandlerSet:
"get_model_versions_status": self.model_library.get_model_versions_status,
"open_file_location": self.filesystem.open_file_location,
"open_settings_location": self.filesystem.open_settings_location,
"get_custom_words": self.custom_words.get_custom_words,
"update_custom_words": self.custom_words.update_custom_words,
"search_custom_words": self.custom_words.search_custom_words,
}

View File

@@ -42,8 +42,6 @@ MISC_ROUTE_DEFINITIONS: tuple[RouteDefinition, ...] = (
RouteDefinition("GET", "/api/lm/metadata-archive-status", "get_metadata_archive_status"),
RouteDefinition("GET", "/api/lm/model-versions-status", "get_model_versions_status"),
RouteDefinition("POST", "/api/lm/settings/open-location", "open_settings_location"),
RouteDefinition("GET", "/api/lm/custom-words", "get_custom_words"),
RouteDefinition("POST", "/api/lm/custom-words", "update_custom_words"),
RouteDefinition("GET", "/api/lm/custom-words/search", "search_custom_words"),
)