General code clean up.

This commit is contained in:
Scott Idem
2021-08-23 12:54:27 -04:00
parent 5606cdb12f
commit 683597e2bf
5 changed files with 19 additions and 17 deletions

View File

@@ -4,7 +4,7 @@ from timeit import default_timer as timer
from app.config import settings
from app.log import log, logging
#from .lib_general import lookup_id_random_pop
# from .lib_general import lookup_id_random_pop
from sqlalchemy import create_engine, text, Time
from sqlalchemy.exc import IntegrityError, OperationalError
@@ -671,7 +671,7 @@ def sql_delete(
# ### BEGIN ### API Lib General ### redis_lookup_id_random() ###
# ### BEGIN ### API DB SQL ### redis_lookup_id_random() ###
# Just return the value if it is an integer
# Check if the id_random value is a string and the correct length
# Attempt to look up id_random key in Redis
@@ -757,11 +757,13 @@ def redis_lookup_id_random(record_id_random:int|str, table_name:str):
# log.setLevel(logging.ERROR) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
log.error('We should not be here. Something unexpected happened.')
return False # Just in case
# ### END ### API Lib General ### redis_lookup_id_random() ###
# ### END ### API DB SQL ### redis_lookup_id_random() ###
# ### BEGIN ### API Lib General ### lookup_id_random() ###
def lookup_id_random(record_id:int, table_name:str):
# ### BEGIN ### API DB SQL ### get_id_random() ###
# Changed name from lookup_id_random() to get_id_random()
# Updated 2021-08-23
def get_id_random(record_id:int, table_name:str):
log.setLevel(logging.DEBUG) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
log.debug(locals())
@@ -793,10 +795,10 @@ def lookup_id_random(record_id:int, table_name:str):
#log.setLevel(logging.INFO) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
log.info('Record ID random was not found')
return None
# ### END ### API Lib General ### lookup_id_random() ###
# ### END ### API DB SQL ### get_id_random() ###
# ### BEGIN ### API Lib General ### lookup_id_random_pop() ###
# ### BEGIN ### API DB SQL ### lookup_id_random_pop() ###
# Look up and resolve id_random values to their id
# Remove the unneeded *_id_random key from the dict
# This really needs to be simplified... Use a list of dicts instead. Can store as JSON in the DB.
@@ -1023,4 +1025,4 @@ def lookup_id_random_pop(obj_data:dict):
obj_data.pop('from_object_id_random')
return obj_data
# ### END ### API Lib General ### lookup_id_random_pop() ###
# ### END ### API DB SQL ### lookup_id_random_pop() ###