feat(api): improve ID resolution in search and enable presenter file count

- In lib_sql_search, added a fallback to resolve random string IDs via Redis
  when the view lacks a dedicated _id_random column.
- Un-commented file_count in Event_Presenter_Out_Base to support file
  tracking for presenters.
This commit is contained in:
Scott Idem
2026-01-29 17:09:41 -05:00
parent 51b24a466a
commit 0de6058639
2 changed files with 13 additions and 5 deletions

View File

@@ -248,10 +248,18 @@ def sql_search_qry_part(
target_field = candidate_field
# print(f"Search Trace: Mapping filter field '{f.field}' -> '{target_field}'", flush=True)
else:
# If random doesn't exist, we must stick to the integer column
# but we'll need to resolve the string value to an integer elsewhere
# or rely on the user providing an integer for now.
pass
# Fallback: Resolve ID if random column is missing from view
try:
from app.lib_redis_helpers import redis_lookup_id_random
# Infer table name (e.g., 'event_id' -> 'event')
if target_field.endswith('_id') and target_field != 'id':
lookup_tbl = target_field[:-3] # remove '_id'
resolved_id = redis_lookup_id_random(record_id_random=f.value, table_name=lookup_tbl)
if resolved_id:
# Update the filter value to use the resolved integer
f.value = resolved_id
except Exception as e:
log.warning(f"Failed to resolve random ID for field {target_field}: {e}")
if searchable_fields is not None and target_field not in searchable_fields:
# Fallback check for original field just in case

View File

@@ -334,7 +334,7 @@ class Event_Presenter_Out_Base(BaseModel):
data_json: Optional[Union[Json, None]] # For key value data. Careful with overwriting existing fields!
cfg_json: Optional[Union[Json, None]] # Store per presenter config options like theme, language, etc
# file_count: Optional[int]
file_count: Optional[int]
# General catchall for agreement or consent
agree: Optional[bool]