diff --git a/intavia_backend/intavia_cache.py b/intavia_backend/intavia_cache.py new file mode 100644 index 0000000..f81b27a --- /dev/null +++ b/intavia_backend/intavia_cache.py @@ -0,0 +1,15 @@ +"""Wrapper around the FastApiCache-2 library""" +import os +from fastapi_cache.decorator import cache + + +def nocache(*args, **kwargs): + def decorator(func): + return func + return decorator + +# I have an .env file, and my get_settings() reads the .env file +if os.environ.get("APIS_REDIS_CACHING", "True") == "True": + cache = cache +else: + cache = nocache \ No newline at end of file diff --git a/intavia_backend/main_v1.py b/intavia_backend/main_v1.py index 721a1fa..ff7bb76 100644 --- a/intavia_backend/main_v1.py +++ b/intavia_backend/main_v1.py @@ -22,7 +22,7 @@ from fastapi_cache import FastAPICache from fastapi_cache.backends.redis import RedisBackend -from fastapi_cache.decorator import cache +from .intavia_cache import cache from .utils import get_query_from_triplestore diff --git a/intavia_backend/main_v2.py b/intavia_backend/main_v2.py index e73753c..4661578 100644 --- a/intavia_backend/main_v2.py +++ b/intavia_backend/main_v2.py @@ -3,7 +3,7 @@ import math import dateutil from fastapi import APIRouter, Depends, HTTPException -from fastapi_cache.decorator import cache +from .intavia_cache import cache import requests from fastapi_versioning import version, versioned_api_route diff --git a/intavia_backend/models_v2.py b/intavia_backend/models_v2.py index 12a8e1f..e348206 100644 --- a/intavia_backend/models_v2.py +++ b/intavia_backend/models_v2.py @@ -85,6 +85,9 @@ def pp_id_provider(field, item, data): it = "/".join(it["id"].split("/")[:-1]) else: it = it["id"] + test_uri_valid = re.match(r"^(https?://.+[a-z])([0-9]+$)", it) + if test_uri_valid: #TODO: this is a hack, should be fixed in the data (none-valid URIs should be removed) + it = f"{test_uri_valid.group(1)}/{test_uri_valid.group(2)}" data["url"] = it for k, v in linked_id_providers.items(): if v["baseUrl"] in it: @@ -200,7 +203,7 @@ class Config: RDF_utils_move_errors_to_top = True -class LinkedId(BaseModel): +class LinkedId(IntaViaBackendBaseModel): label: str url: HttpUrl