Minor changes. Temporarily disabled redis...

This commit is contained in:
Scott Idem
2024-02-20 19:14:05 -05:00
parent dca4175659
commit d6787f9855
3 changed files with 54 additions and 6 deletions

View File

@@ -1214,6 +1214,15 @@ def redis_lookup_id_random(
record_id = r.get(key_name) record_id = r.get(key_name)
log.debug(f'Record ID found: {record_id}') log.debug(f'Record ID found: {record_id}')
# WARNING WARNING WARNING
# WARNING WARNING WARNING
# WARNING WARNING WARNING
log.info(f'Looking up ID in Redis is being partially bypassed. Key="{key_name}" value="{record_id}" TTL={r.ttl(key_name)} seconds')
record_id = None
# WARNING WARNING WARNING
# WARNING WARNING WARNING
# WARNING WARNING WARNING
if record_id: if record_id:
# log.info('The record ID was found using the record_id_random value.') # log.info('The record ID was found using the record_id_random value.')
# r.setex(key_name, datetime.timedelta(minutes=1), value=record_id) # r.setex(key_name, datetime.timedelta(minutes=1), value=record_id)
@@ -1494,6 +1503,14 @@ def lookup_id_random_pop(
obj_data['product_id'] = redis_lookup_id_random(record_id_random=obj_data['product_id_random'], table_name='product') obj_data['product_id'] = redis_lookup_id_random(record_id_random=obj_data['product_id_random'], table_name='product')
obj_data.pop('product_id_random') obj_data.pop('product_id_random')
if 'sponsorship_id_random' in obj_data:
obj_data['sponsorship_id'] = redis_lookup_id_random(record_id_random=obj_data['sponsorship_id_random'], table_name='sponsorship')
obj_data.pop('sponsorship_id_random')
if 'sponsorship_cfg_id_random' in obj_data:
obj_data['sponsorship_cfg_id'] = redis_lookup_id_random(record_id_random=obj_data['sponsorship_cfg_id_random'], table_name='sponsorship')
obj_data.pop('sponsorship_cfg_id_random')
if 'site_id_random' in obj_data: if 'site_id_random' in obj_data:
obj_data['site_id'] = redis_lookup_id_random(record_id_random=obj_data['site_id_random'], table_name='site') obj_data['site_id'] = redis_lookup_id_random(record_id_random=obj_data['site_id_random'], table_name='site')
obj_data.pop('site_id_random') obj_data.pop('site_id_random')

View File

@@ -32,7 +32,6 @@ class Hosted_File_Base(BaseModel):
version: Optional[int] version: Optional[int]
directory_path: Optional[str]
subdirectory_path: Optional[str] # NOTE: This will frequently only contain numbers, but it still needs to be a string subdirectory_path: Optional[str] # NOTE: This will frequently only contain numbers, but it still needs to be a string
filename: Optional[str] filename: Optional[str]
extension: Optional[str] extension: Optional[str]
@@ -40,11 +39,11 @@ class Hosted_File_Base(BaseModel):
mimetype: Optional[str] mimetype: Optional[str]
size: Optional[int] # In bytes size: Optional[int] # In bytes
cloud_storage: Optional[str] # cloud_storage: Optional[str]
owner_user_id: Optional[int] # owner_user_id: Optional[int]
group_user_id: Optional[str] # group_user_id: Optional[str]
package_name: Optional[str] # package_name: Optional[str]
already_exists: Optional[str] # This will probably only be populated on upload results already_exists: Optional[str] # This will probably only be populated on upload results
copy_timer: Optional[str] # This will probably only be populated on upload results copy_timer: Optional[str] # This will probably only be populated on upload results

View File

@@ -3,7 +3,7 @@ import datetime, pytz
from typing import Dict, List, Optional, Set, Union from typing import Dict, List, Optional, Set, Union
from pydantic import BaseModel, EmailStr, Field, Json, PrivateAttr, ValidationError, validator from pydantic import BaseModel, EmailStr, Field, Json, PrivateAttr, ValidationError, validator
from app.db_sql import redis_lookup_id_random from app.db_sql import get_id_random, redis_lookup_id_random
from app.lib_general import log, logging from app.lib_general import log, logging
from app.models.common_field_schema import base_fields, default_num_bytes from app.models.common_field_schema import base_fields, default_num_bytes
@@ -31,6 +31,7 @@ class Sponsorship_Cfg_Base(BaseModel):
for_type: Optional[str] for_type: Optional[str]
for_id: Optional[int] for_id: Optional[int]
for_id_random: Optional[str] # This should be after for_id if we want for_id_random filled in.
# For levels in a JSON object list format. A level option should contain: num, str, name, desc. Example: {"num": 1, "code": "platinum", "name": "Platinum", "desc": "Platinum Sponsorship"} # For levels in a JSON object list format. A level option should contain: num, str, name, desc. Example: {"num": 1, "code": "platinum", "name": "Platinum", "desc": "Platinum Sponsorship"}
level_li_json: Optional[Union[Json, None]] level_li_json: Optional[Union[Json, None]]
@@ -93,6 +94,37 @@ class Sponsorship_Cfg_Base(BaseModel):
return redis_lookup_id_random(record_id_random=id_random, table_name='account') return redis_lookup_id_random(record_id_random=id_random, table_name='account')
return None return None
@validator('for_id', always=True)
def for_id_lookup(cls, v, values, **kwargs):
log.setLevel(logging.WARNING)
log.debug(locals())
if isinstance(v, int) and v > 0: return v
elif values.get('for_id_random') and values.get('for_type'):
for_id_random = values.get('for_id_random')
for_type = values.get('for_type')
return redis_lookup_id_random(record_id_random=for_id_random, table_name=for_type)
return None
@validator('for_id_random', always=True)
def for_id_random_lookup(cls, v, values, **kwargs):
log.setLevel(logging.DEBUG)
log.debug(locals())
for_type = values.get('for_type')
for_id = values.get('for_id')
for_id_random = v
if for_id_random:
log.info(f'Got For ID Random: {for_id_random}')
return for_id_random
elif for_id and for_type:
log.info(f'Got For ID: {for_id}; For Type: {for_type}')
for_id_random = get_id_random(for_id, table_name=for_type)
log.info(f'Got ID Random: {for_id_random}')
return for_id_random
log.info(f'Got nothing? For ID: {for_id}; For ID Random: {for_id_random}; For Type: {for_type}')
return None
class Config: class Config:
underscore_attrs_are_private = True underscore_attrs_are_private = True
allow_population_by_field_name = True allow_population_by_field_name = True