Skip to content

Investigate reducing overhead caused by HrefPrnFieldMixin #7661

@dralley

Description

@dralley

The overhead of HrefPrnFieldMixin is surprisingly high, being actually significant (10-20%) of the total time required during uploading of RPM packages using the synchronous APIs, and perhaps in other circumstances also.

class HrefPrnFieldMixin:
"""A mixin to configure related fields to generate relative hrefs and accept PRNs."""
def get_url(self, obj, view_name, request, *args, **kwargs):
# Use the Pulp reverse method to display relative hrefs.
self.reverse = _reverse(obj)
return super().get_url(obj, view_name, request, *args, **kwargs)
def to_internal_value(self, data):
# Properly also handle PRNs as values by converting them to URLs first
if data.startswith("prn:"):
model, pk = resolve_prn(data)
obj = model(pk=pk) if self.use_pk_only_optimization() else model.objects.get(pk=pk)
data = self.get_url(obj, self.view_name, self.context.get("request"), None)
return super().to_internal_value(data)

First noted in a prior PR: #6693 (comment)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions