mirror of
https://github.com/vladmandic/automatic
synced 2026-09-19 17:24:32 +02:00
feat(civitai): record search filters in history entries
History entries stored only the query or tag term, so restoring a search dropped every filter, and filter-only browsing was never recorded at all. - SearchHistory.add takes an optional params dict stored on the entry - get_search records non-default filters: type, sort, period, base models, nsfw, username, favorites - filter-only searches are recorded as 'filter' entries labeled with the filter values
This commit is contained in:
@@ -103,10 +103,31 @@ def get_search(
|
||||
base_models=bm_list, nsfw=nsfw, limit=limit, cursor=cursor,
|
||||
username=username, favorites=favorites, token=token,
|
||||
)
|
||||
history_params = {k: v for k, v in {
|
||||
'types': types,
|
||||
'sort': sort,
|
||||
'period': period,
|
||||
'base_models': base_models,
|
||||
'nsfw': nsfw,
|
||||
'username': username,
|
||||
'favorites': favorites,
|
||||
}.items() if v}
|
||||
if query:
|
||||
search_history.add('query', query)
|
||||
search_history.add('query', query, history_params)
|
||||
elif tag:
|
||||
search_history.add('tag', tag)
|
||||
search_history.add('tag', tag, history_params)
|
||||
elif history_params:
|
||||
# Filter-only browse: label the entry with the filters themselves.
|
||||
parts = [
|
||||
types,
|
||||
base_models,
|
||||
'favorites' if favorites else (f'by {username}' if username else ''),
|
||||
period,
|
||||
sort,
|
||||
'nsfw' if nsfw else '',
|
||||
]
|
||||
label = ' · '.join(p for p in parts if p)
|
||||
search_history.add('filter', label, history_params)
|
||||
return response.dict(by_alias=True)
|
||||
|
||||
|
||||
|
||||
@@ -96,13 +96,15 @@ class SearchHistory:
|
||||
except Exception as e:
|
||||
log.error(f'CivitAI search history save error: file={path} {e}')
|
||||
|
||||
def add(self, search_type: str, term: str):
|
||||
def add(self, search_type: str, term: str, params: dict | None = None):
|
||||
with self._lock:
|
||||
entry = {
|
||||
"type": search_type,
|
||||
"term": term,
|
||||
"timestamp": datetime.now().isoformat(),
|
||||
}
|
||||
if params:
|
||||
entry["params"] = params
|
||||
# Remove duplicate if same type+term exists
|
||||
self._entries = [e for e in self._entries if not (e.get('type') == search_type and e.get('term') == term)]
|
||||
self._entries.insert(0, entry)
|
||||
|
||||
Reference in New Issue
Block a user