Skip to content

Commit

Permalink
serializers: replace slugs caching with invenio-cache
Browse files Browse the repository at this point in the history
  • Loading branch information
ntarocco committed Oct 2, 2023
1 parent fd4a8a4 commit 78e0098
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 17 deletions.
7 changes: 1 addition & 6 deletions invenio_rdm_records/resources/serializers/datacite/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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(
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@

"""Dublin Core based Schema for Invenio RDM Records."""

import time

import bleach
import idutils
from flask import current_app
Expand Down Expand Up @@ -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"))

Expand Down
6 changes: 1 addition & 5 deletions invenio_rdm_records/resources/serializers/marcxml/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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):
Expand Down

0 comments on commit 78e0098

Please sign in to comment.