From 09c48b20e866e4e696e612f2ea3209376c9e9d08 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20S=C3=A1nchez-Gallego?= Date: Thu, 12 Dec 2024 18:11:10 -0800 Subject: [PATCH] Set custom cache namespaces for target and query routes --- python/valis/cache.py | 2 +- python/valis/routes/query.py | 16 ++++++++-------- python/valis/routes/target.py | 8 ++++---- 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/python/valis/cache.py b/python/valis/cache.py index 74f8380..94b4db8 100644 --- a/python/valis/cache.py +++ b/python/valis/cache.py @@ -65,7 +65,7 @@ logger = logging.getLogger("uvicorn.error") -print(settings.cache_ttl, type(settings.cache_ttl)) + @asynccontextmanager async def lifespan(_: FastAPI) -> AsyncIterator[None]: backend = settings.cache_backend diff --git a/python/valis/routes/query.py b/python/valis/routes/query.py index d5e42be..4459245 100644 --- a/python/valis/routes/query.py +++ b/python/valis/routes/query.py @@ -84,7 +84,7 @@ class QueryRoutes(Base): dependencies=[Depends(get_pw_db)], response_model=MainSearchResponse, response_model_exclude_unset=True, response_model_exclude_none=True) - @valis_cache() + @valis_cache(namespace='valis-query') async def main_search(self, body: SearchModel): """ Main query for UI and for combining queries together """ @@ -127,7 +127,7 @@ async def main_search(self, body: SearchModel): @router.get('/cone', summary='Perform a cone search for SDSS targets with sdss_ids', response_model=List[SDSSModel], dependencies=[Depends(get_pw_db)]) - @valis_cache() + @valis_cache(namespace='valis-query') async def cone_search(self, ra: Annotated[Union[float, str], Query(description='Right Ascension in degrees or hmsdms', example=315.78)], dec: Annotated[Union[float, str], Query(description='Declination in degrees or hmsdms', example=-3.2)], @@ -144,7 +144,7 @@ async def cone_search(self, @router.get('/sdssid', summary='Perform a search for an SDSS target based on the sdss_id', response_model=Union[SDSSidStackedBase, dict], dependencies=[Depends(get_pw_db)]) - @valis_cache() + @valis_cache(namespace='valis-query') async def sdss_id_search(self, sdss_id: Annotated[int, Query(description='Value of sdss_id', example=47510284)]): """ Perform an sdss_id search. @@ -176,7 +176,7 @@ async def catalog_id_search(self, catalog_id: Annotated[int, Query(description=' @router.get('/list/cartons', summary='Return a list of all cartons', response_model=list, dependencies=[Depends(get_pw_db)]) - @valis_cache() + @valis_cache(namespace='valis-query') async def cartons(self): """ Return a list of all carton or programs """ @@ -184,7 +184,7 @@ async def cartons(self): @router.get('/list/programs', summary='Return a list of all programs', response_model=list, dependencies=[Depends(get_pw_db)]) - @valis_cache() + @valis_cache(namespace='valis-query') async def programs(self): """ Return a list of all carton or programs """ @@ -192,7 +192,7 @@ async def programs(self): @router.get('/list/program-map', summary='Return a mapping of cartons in all programs', response_model=Dict[str, List[str]], dependencies=[Depends(get_pw_db)]) - @valis_cache() + @valis_cache(namespace='valis-query') async def program_map(self): """ Return a mapping of cartons in all programs """ @@ -200,7 +200,7 @@ async def program_map(self): @router.get('/list/parents', summary='Return a list of available parent catalog tables', response_model=List[str]) - @valis_cache() + @valis_cache(namespace='valis-query') async def parent_catalogs(self): """Return a list of available parent catalog tables.""" @@ -214,7 +214,7 @@ async def parent_catalogs(self): @router.get('/carton-program', summary='Search for all SDSS targets within a carton or program', response_model=List[SDSSModel], dependencies=[Depends(get_pw_db)]) - @valis_cache() + @valis_cache(namespace='valis-query') async def carton_program(self, name: Annotated[str, Query(description='Carton or program name', example='manual_mwm_tess_ob')], name_type: Annotated[str, diff --git a/python/valis/routes/target.py b/python/valis/routes/target.py index 976650c..29a8bed 100644 --- a/python/valis/routes/target.py +++ b/python/valis/routes/target.py @@ -183,7 +183,7 @@ async def get_target_altid(self, @router.get('/spectra/{sdss_id}', summary='Retrieve a spectrum for a target sdss_id', dependencies=[Depends(get_pw_db)], response_model=List[SpectrumModel]) - @valis_cache() + @valis_cache(namespace='valis-target') async def get_spectrum(self, sdss_id: Annotated[int, Path(title="The sdss_id of the target to get", example=23326)], product: Annotated[str, Query(description='The file species or data product name', example='specLite')], ext: Annotated[str, Query(description='For multi-extension spectra, e.g. mwmStar, the name of the spectral extension', example='BOSS/APO')] = None, @@ -194,7 +194,7 @@ async def get_spectrum(self, sdss_id: Annotated[int, Path(title="The sdss_id of dependencies=[Depends(get_pw_db)], response_model=List[CatalogResponse], response_model_exclude_unset=True, response_model_exclude_none=True) - @valis_cache() + @valis_cache(namespace='valis-target') async def get_catalogs(self, sdss_id: int = Path(title="The sdss_id of the target to get", example=23326)): """ Return catalog information for a given sdss_id """ @@ -243,7 +243,7 @@ async def get_parents(self, dependencies=[Depends(get_pw_db)], response_model=List[CartonModel], response_model_exclude_unset=True, response_model_exclude_none=True) - @valis_cache() + @valis_cache(namespace='valis-target') async def get_cartons(self, sdss_id: int = Path(title="The sdss_id of the target to get", example=23326)): """ Return carton information for a given sdss_id """ return get_target_cartons(sdss_id).dicts().iterator() @@ -252,7 +252,7 @@ async def get_cartons(self, sdss_id: int = Path(title="The sdss_id of the target dependencies=[Depends(get_pw_db)], response_model=PipesModel, response_model_exclude_unset=True) - @valis_cache() + @valis_cache(namespace='valis-target') async def get_pipeline(self, sdss_id: int = Path(title="The sdss_id of the target to get", example=23326), pipe: Annotated[str, Query(enum=['all', 'boss', 'apogee', 'astra'],