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)
The overhead of
HrefPrnFieldMixinis 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.pulpcore/pulpcore/app/serializers/base.py
Lines 66 to 80 in f53976e
First noted in a prior PR: #6693 (comment)