diff --git a/rero_ils/modules/cli/utils.py b/rero_ils/modules/cli/utils.py index 4c1082ebbb..59dc7e1a23 100644 --- a/rero_ils/modules/cli/utils.py +++ b/rero_ils/modules/cli/utils.py @@ -273,7 +273,9 @@ def add_org_lib_doc(item, doc_pid="dummy"): return item -@cached() +@cached( + timeout=2 * 60 * 60, key_refix="doc_item_lofi_schemas", query_string=True +) # 2 hour timeout def get_doc_item_lofi_schemas(): """Get document, item, local field schemas.""" # document schema diff --git a/rero_ils/modules/documents/api_views.py b/rero_ils/modules/documents/api_views.py index 21325e45b9..20696d0af4 100644 --- a/rero_ils/modules/documents/api_views.py +++ b/rero_ils/modules/documents/api_views.py @@ -35,7 +35,7 @@ @api_blueprint.route("/cover/") -@cached(timeout=300, query_string=True) +@cached(timeout=5 * 60, query_string=True) # 5 minutes timeout def cover(isbn): """Document cover service.""" return jsonify(get_remote_cover(isbn)) @@ -51,7 +51,7 @@ def document_availability(pid): @api_blueprint.route("/advanced-search-config") -@cached(timeout=300, query_string=True) +@cached(timeout=5 * 60, query_string=True) # 5 minutes timeout @check_logged_as_librarian def advanced_search_config(): """Advanced search config.""" diff --git a/rero_ils/modules/documents/utils.py b/rero_ils/modules/documents/utils.py index 895248346c..2f431f66e2 100644 --- a/rero_ils/modules/documents/utils.py +++ b/rero_ils/modules/documents/utils.py @@ -29,12 +29,14 @@ from werkzeug.local import LocalProxy from ...utils import get_i18n_supported_languages -from ..utils import get_schema_for_resource, memoize +from ..utils import cached, get_schema_for_resource _records_state = LocalProxy(lambda: current_app.extensions["invenio-records"]) -@memoize(timeout=3600) +@cached( + timeout=60 * 60, key_prefix="document_types_from_schema", query_string=True +) # 1 hour timeout def get_document_types_from_schema(schema="doc"): """Create document type definition from schema.""" path = current_jsonschemas.url_to_path(get_schema_for_resource(schema)) diff --git a/rero_ils/modules/utils.py b/rero_ils/modules/utils.py index 75e0db8c27..c6e9f6c8bb 100644 --- a/rero_ils/modules/utils.py +++ b/rero_ils/modules/utils.py @@ -108,27 +108,6 @@ def wrapper(*args, **kwargs): return caching -def memoize(timeout=50): - """Memoize functions. - - Use this to cache the result of a function, taking its arguments into - account in the cache key. - - :param timeout: Default 50. If set to an integer, will cache for that - amount of time. Unit of time is in seconds. - """ - - def memoize(f): - @wraps(f) - def wrapper(*args, **kwargs): - memoize_fun = current_cache.memoize(timeout=timeout) - return memoize_fun(f)(*args, **kwargs) - - return wrapper - - return memoize - - def strtotime(strtime): """String to datetime.""" splittime = strtime.split(":") diff --git a/rero_ils/modules/views.py b/rero_ils/modules/views.py index 4ec02ff04b..00a7b5b772 100644 --- a/rero_ils/modules/views.py +++ b/rero_ils/modules/views.py @@ -51,7 +51,7 @@ @api_blueprint.route("/permissions/", methods=["GET"]) @api_blueprint.route("/permissions//", methods=["GET"]) -@cached(timeout=10, query_string=True) +@cached(timeout=10, query_string=True) # 10 seconds timeout @check_authentication def permissions(route_name, record_pid=None): """HTTP GET request for record permissions. diff --git a/rero_ils/theme/views.py b/rero_ils/theme/views.py index a53a75efaf..e203f01ab8 100644 --- a/rero_ils/theme/views.py +++ b/rero_ils/theme/views.py @@ -85,8 +85,8 @@ def error(): @blueprint.route("/robots.txt") -@cached() -def robots(timeout=60 * 60): # 1 hour timeout +@cached(timeout=60 * 60, query_string=True) # 1 hour timeout +def robots(): """Robots.txt generate response.""" response = current_app.config["RERO_ILS_ROBOTS"] response = Response(response=response, status=200, mimetype="text/plain") diff --git a/tests/unit/test_cli_utils.py b/tests/unit/test_cli_utils.py index c7af1d6c30..b14287c0c8 100644 --- a/tests/unit/test_cli_utils.py +++ b/tests/unit/test_cli_utils.py @@ -74,7 +74,6 @@ def test_cli_validate_documents_items_lofi(app, loc_public_martigny): file_name = join(dirname(__file__), "../data/documents_items_lofi.json") res = runner.invoke(validate_documents_with_items_lofis_cli, [file_name, "-v"]) - print(">>>>", res) assert res.output.strip().split("\n")[1:] == [ "1 document: dummy_1 errors: 1", " documents: 'type' is a required property",