[PATCH] REST: allow fetching of subject prefixes (categories)

Daniel Axtens dja at axtens.net
Tue Feb 21 16:16:14 AEDT 2017


>> +    def get_categories(self, instance):
>> +        return clean_subject(instance.name)[1]
>
> This is going to run for 'page_size' patches on the list operation. I
> don't know how expensive each run is but seeing as there are regexes
> involved I doubt it's free. I wonder if we should access this via a
> 'cached_property' field on 'Submission'?

So I had a look at this: the cached property is calculated each time I
hit refresh, so I don't think we're going to get a big win here by
moving this logic.

We don't have a caching layer that would store these things across
requests, and we don't have any logic for invalidating them, so there's
no easy fix to this. (I'm pretty sure putting it in the database would
be even slower!)

We could possibly move this into the detail view. Andrew or Russell:
would that work for you?

Regards,
Daniel

>
>>      def get_mbox(self, instance):
>>          request = self.context.get('request')
>> @@ -100,10 +105,10 @@ class
>> PatchListSerializer(HyperlinkedModelSerializer):
>>          fields = ('id', 'url', 'project', 'msgid', 'date', 'name',
>>                    'commit_ref', 'pull_url', 'state', 'archived',
>> 'hash',
>>                    'submitter', 'delegate', 'mbox', 'series',
>> 'check', 'checks',
>> -                  'tags')
>> +                  'tags', 'categories')
>
> I'm not sure about 'categories' - this will also return things like the
> version ('v2') and the number of the patch if it's in a series ('1/5'),
> correct? Labels might be more valid, if so (though I had planned to use
> that name for a more significant feature in v2.1 or so [1]).
>
>>          read_only_fields = ('project', 'msgid', 'date', 'name',
>> 'hash',
>>                              'submitter', 'mbox', 'mbox', 'series',
>> 'check',
>> -                            'checks', 'tags')
>> +                            'checks', 'tags', 'categories')
>
> Do we want to be able to filter on these? I don't know if you can do
> this for non-model fields though...
>
>>          extra_kwargs = {
>>              'url': {'view_name': 'api-patch-detail'},
>>              'project': {'view_name': 'api-project-detail'},
>
> Stephen
>
> [1] https://github.com/getpatchwork/patchwork/issues/22


More information about the Patchwork mailing list