Skip to content

Commit

Permalink
Set custom cache namespaces for target and query routes
Browse files Browse the repository at this point in the history
  • Loading branch information
albireox committed Dec 13, 2024
1 parent 1d8a6a5 commit 09c48b2
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 13 deletions.
2 changes: 1 addition & 1 deletion python/valis/cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 8 additions & 8 deletions python/valis/routes/query.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 """

Expand Down Expand Up @@ -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)],
Expand All @@ -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.
Expand Down Expand Up @@ -176,31 +176,31 @@ 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 """

return carton_program_list("carton")

@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 """

return carton_program_list("program")

@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 """

return carton_program_map()

@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."""

Expand All @@ -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,
Expand Down
8 changes: 4 additions & 4 deletions python/valis/routes/target.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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 """

Expand Down Expand Up @@ -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()
Expand All @@ -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'],
Expand Down

0 comments on commit 09c48b2

Please sign in to comment.