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:
@@ -248,10 +248,18 @@ def sql_search_qry_part(
|
|||||||
target_field = candidate_field
|
target_field = candidate_field
|
||||||
# print(f"Search Trace: Mapping filter field '{f.field}' -> '{target_field}'", flush=True)
|
# print(f"Search Trace: Mapping filter field '{f.field}' -> '{target_field}'", flush=True)
|
||||||
else:
|
else:
|
||||||
# If random doesn't exist, we must stick to the integer column
|
# Fallback: Resolve ID if random column is missing from view
|
||||||
# but we'll need to resolve the string value to an integer elsewhere
|
try:
|
||||||
# or rely on the user providing an integer for now.
|
from app.lib_redis_helpers import redis_lookup_id_random
|
||||||
pass
|
# 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:
|
if searchable_fields is not None and target_field not in searchable_fields:
|
||||||
# Fallback check for original field just in case
|
# Fallback check for original field just in case
|
||||||
|
|||||||
@@ -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!
|
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
|
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
|
# General catchall for agreement or consent
|
||||||
agree: Optional[bool]
|
agree: Optional[bool]
|
||||||
|
|||||||
Reference in New Issue
Block a user