Skip to content

Commit ab6e1db

Browse files
Yuri ZmytrakovYuri Zmytrakov
authored andcommitted
fix: apply recommendations
1 parent 5f87131 commit ab6e1db

File tree

1 file changed

+18
-11
lines changed
  • stac_fastapi/core/stac_fastapi/core

1 file changed

+18
-11
lines changed

stac_fastapi/core/stac_fastapi/core/core.py

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
from stac_pydantic.links import Relations
2020
from stac_pydantic.shared import BBox, MimeTypes
2121
from stac_pydantic.version import STAC_VERSION
22+
from stac_fastapi.core.utilities import get_bool_env
2223

2324
from stac_fastapi.core.base_database_logic import BaseDatabaseLogic
2425
from stac_fastapi.core.base_settings import ApiBaseSettings
@@ -277,11 +278,13 @@ async def all_collections(
277278
sort = parsed_sort
278279

279280
current_url = str(request.url)
280-
redis = None
281-
try:
282-
redis = await connect_redis_sentinel()
283-
except Exception:
284-
redis = None
281+
redis_enable = get_bool_env("REDIS_ENABLE", default=False)
282+
283+
if redis_enable:
284+
try:
285+
redis = await connect_redis_sentinel()
286+
except Exception:
287+
redis = None
285288

286289
# Convert q to a list if it's a string
287290
q_list = None
@@ -311,7 +314,7 @@ async def all_collections(
311314
},
312315
]
313316

314-
if redis:
317+
if redis_enable and redis:
315318
if next_token:
316319
await save_self_link(redis, next_token, current_url)
317320

@@ -557,10 +560,14 @@ async def post_search(
557560
HTTPException: If there is an error with the cql2_json filter.
558561
"""
559562
base_url = str(request.base_url)
560-
try:
561-
redis = await connect_redis_sentinel()
562-
except Exception:
563-
redis = None
563+
redis_enable = get_bool_env("REDIS_ENABLE", default=False)
564+
565+
redis = None
566+
if redis_enable:
567+
try:
568+
redis = await connect_redis_sentinel()
569+
except Exception:
570+
redis = None
564571

565572
search = self.database.make_search()
566573

@@ -690,7 +697,7 @@ async def post_search(
690697
)
691698
links.extend(collection_links)
692699

693-
if redis:
700+
if redis_enable and redis:
694701
self_link = str(request.url)
695702
await save_self_link(redis, next_token, self_link)
696703

0 commit comments

Comments
 (0)