fix(services): implement stable sorting for model and recipe caches

Add file_path as a tie-breaker for all sort modes in ModelCache, BaseModelService, LoraService, and RecipeCache to ensure deterministic ordering when primary keys are identical. Resolves issue #859.
This commit is contained in:
Will Miao
2026-03-17 14:20:23 +08:00
parent 9e81c33f8a
commit 70c150bd80
4 changed files with 35 additions and 12 deletions

View File

@@ -135,7 +135,8 @@ class RecipeCache:
"""Sort cached views. Caller must hold ``_lock``."""
self.sorted_by_name = natsorted(
self.raw_data, key=lambda x: x.get("title", "").lower()
self.raw_data,
key=lambda x: (x.get("title", "").lower(), x.get("file_path", "").lower()),
)
if not name_only:
self.sorted_by_date = sorted(