Improve data store record retrieval.

This commit is contained in:
Scott Idem
2023-05-22 13:41:30 -04:00
parent b9b45969f3
commit 0375bd8c05
5 changed files with 95 additions and 7 deletions

View File

@@ -55,6 +55,8 @@ def load_data_store_obj(
def load_data_store_obj_w_code(
account_id: int,
code: str,
for_type: int = None,
for_id: int = None,
enabled: str = 'enabled', # enabled, disabled, all
limit: int = 1,
offset: int = 0,
@@ -68,9 +70,18 @@ def load_data_store_obj_w_code(
data = {}
data['account_id'] = account_id
data['code'] = code
data['for_type'] = for_type
data['for_id'] = for_id
log.debug(data)
# log.warning(f'Can we get past this?????????? {code}')
# if for_id := redis_lookup_id_random(record_id_random=for_id, table_name=for_type): pass
# else: return False
if for_type and for_id:
sql_for_type_id = 'AND `data_store`.for_type = :for_type AND `data_store`.for_id = :for_id'
else:
sql_for_type_id = 'AND `data_store`.for_type IS NULL AND `data_store`.for_id IS NULL'
sql_enabled, data['enable'] = sql_enable_part(table_name='data_store', enabled=enabled) # Reasonably safe return str and bool
sql_limit = sql_limit_offset_part(limit=limit, offset=offset) # Reasonably safe return str
@@ -87,6 +98,7 @@ def load_data_store_obj_w_code(
OR `data_store`.account_id IS NULL
)
AND `data_store`.code = :code
{sql_for_type_id}
{sql_enabled}
ORDER BY `data_store`.account_id DESC, `data_store`.created_on DESC, `data_store`.updated_on DESC
{sql_limit};

View File

@@ -173,7 +173,7 @@ def get_event_abstract_rec_list(
if event_id:
data['event_id'] = event_id
sql_event_id = f'AND `event_abstract`.event_id = :event_id'
sql_event_id = f'`event_abstract`.event_id = :event_id'
else: sql_event_id = '1=1'
if event_person_id: