Skip to content

Commit

Permalink
Set cache configs for both graph loading and results
Browse files Browse the repository at this point in the history
  • Loading branch information
kkaris committed Aug 16, 2024
1 parent f439dd9 commit c1cbd2a
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions indra_network_search/rest_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@

NAME = "INDRA Network Search"
VERSION = "1.0.0"
TRUTHINESS = ("1", "true", "t")

app = FastAPI(
title=NAME,
Expand All @@ -54,8 +55,9 @@
allow_headers=["*"],
)

DEBUG = environ.get("API_DEBUG") == "1"
USE_CACHE = environ.get("USE_CACHE") == "1"
DEBUG = environ.get("API_DEBUG").lower() in TRUTHINESS
USE_GRAPH_CACHE = environ.get("USE_CACHE") in TRUTHINESS
CACHE_RESULTS = environ.get("CACHE_RESULTS") in TRUTHINESS
HEALTH = Health(status="booting")
STATUS = ServerStatus(status="booting", graph_date="2022-01-11")
network_search_api: IndraNetworkSearchAPI
Expand Down Expand Up @@ -227,7 +229,11 @@ def query(search_query: NetworkSearchQuery, background_tasks: BackgroundTasks):
logger.info(f"Got NetworkSearchQuery #{query_hash}: {search_query.dict()}")

# Check if results are on S3
keys_dict = check_existence_and_date_s3(query_hash=query_hash)
if CACHE_RESULTS:
keys_dict = check_existence_and_date_s3(query_hash=query_hash)
else:
keys_dict = {}

if keys_dict.get("result_json_key"):
logger.info("Found results cached on S3")
results_json = file_opener(keys_dict["result_json_key"])
Expand Down Expand Up @@ -301,7 +307,7 @@ def startup_event():
unsigned_multi_graph=False,
sign_node_graph=True,
sign_edge_graph=False,
use_cache=USE_CACHE,
use_cache=USE_GRAPH_CACHE,
)

try:
Expand Down

0 comments on commit c1cbd2a

Please sign in to comment.