Skip to content

Commit

Permalink
communities: use cached slug
Browse files Browse the repository at this point in the history
* closes #539
  • Loading branch information
ntarocco committed Sep 28, 2023
1 parent 2b6ec1d commit 9e5a266
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions site/zenodo_rdm/legacy/serializers/schemas/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"""Zenodo common serializer schemas."""

from invenio_communities.proxies import current_communities
from invenio_communities.communities.services.service import get_cached_community_slug
from marshmallow import Schema, fields, missing, post_dump, pre_dump
from marshmallow_utils.fields import EDTFDateString, SanitizedHTML, SanitizedUnicode
from zenodo_legacy.funders import FUNDER_ACRONYMS, FUNDER_ROR_TO_DOI
Expand Down Expand Up @@ -192,13 +193,11 @@ def resolve_communities(self, data, **kwargs):
parent_communities = (
data.get("parent", {}).get("communities", {}).get("ids", [])
)
community_cls = current_communities.service.record_cls
service_id = current_communities.service.id
for community_id in parent_communities:
# NOTE: This is bery bad, we're performing DB queries for every community ID
# in order to resolve the slug required by the legacy API.
try:
community = community_cls.pid.resolve(community_id)
community_slugs.add(community.slug)
slug = get_cached_community_slug(community_id, service_id)
community_slugs.add(slug)
except Exception:
pass
if community_slugs:
Expand Down

0 comments on commit 9e5a266

Please sign in to comment.