From 78e0098dc4ab78f7357179f8413986b9f3bf2c4d Mon Sep 17 00:00:00 2001 From: Nicola Tarocco Date: Mon, 2 Oct 2023 17:46:51 +0200 Subject: [PATCH] serializers: replace slugs caching with invenio-cache --- .../resources/serializers/datacite/schema.py | 7 +------ .../resources/serializers/dublincore/schema.py | 7 +------ .../resources/serializers/marcxml/schema.py | 6 +----- 3 files changed, 3 insertions(+), 17 deletions(-) diff --git a/invenio_rdm_records/resources/serializers/datacite/schema.py b/invenio_rdm_records/resources/serializers/datacite/schema.py index bbf6e3ece..43c707880 100644 --- a/invenio_rdm_records/resources/serializers/datacite/schema.py +++ b/invenio_rdm_records/resources/serializers/datacite/schema.py @@ -9,8 +9,6 @@ """DataCite based Schema for Invenio RDM Records.""" -import time - from edtf import parse_edtf from edtf.parser.grammar import ParseException from flask import current_app @@ -436,11 +434,8 @@ def get_related_identifiers(self, obj): # adding communities communities = obj.get("parent", {}).get("communities", {}).get("ids", []) service_id = current_communities.service.id - one_hour_cache = round(time.time() / 3600) for community_id in communities: - slug = get_cached_community_slug( - community_id, service_id, ttl_hash=one_hour_cache - ) + slug = get_cached_community_slug(community_id, service_id) url = f"{current_app.config['SITE_UI_URL']}/communities/{slug}" serialized_identifiers.append( { diff --git a/invenio_rdm_records/resources/serializers/dublincore/schema.py b/invenio_rdm_records/resources/serializers/dublincore/schema.py index 4531d8b76..b7630d0a0 100644 --- a/invenio_rdm_records/resources/serializers/dublincore/schema.py +++ b/invenio_rdm_records/resources/serializers/dublincore/schema.py @@ -7,8 +7,6 @@ """Dublin Core based Schema for Invenio RDM Records.""" -import time - import bleach import idutils from flask import current_app @@ -107,11 +105,8 @@ def get_relations(self, obj): # Communities communities = obj["parent"].get("communities", {}).get("ids", []) service_id = current_communities.service.id - one_hour_cache = round(time.time() / 3600) for community_id in communities: - slug = get_cached_community_slug( - community_id, service_id, ttl_hash=one_hour_cache - ) + slug = get_cached_community_slug(community_id, service_id) url = f"{current_app.config['SITE_UI_URL']}/communities/{slug}" rels.append(self._transform_identifier(url, "url")) diff --git a/invenio_rdm_records/resources/serializers/marcxml/schema.py b/invenio_rdm_records/resources/serializers/marcxml/schema.py index ba579d429..2e4871cec 100644 --- a/invenio_rdm_records/resources/serializers/marcxml/schema.py +++ b/invenio_rdm_records/resources/serializers/marcxml/schema.py @@ -7,8 +7,6 @@ """MARCXML based Schema for Invenio RDM Records.""" -import time - import bleach from dateutil.parser import parse from flask import current_app, g @@ -133,10 +131,8 @@ def get_sizes(self, obj): def _get_communities_slugs(self, ids): """Get communities slugs.""" service_id = current_communities.service.id - one_hour_cache = round(time.time() / 3600) return [ - get_cached_community_slug(community_id, service_id, ttl_hash=one_hour_cache) - for community_id in ids + get_cached_community_slug(community_id, service_id) for community_id in ids ] def get_communities(self, obj):