Skip to content

Extra queries when warming with VersatileImageFieldWarmer #201

@Ptosiek

Description

@Ptosiek

Hi,
First, thanks for the lib!
In VersatileImageFieldWarmer.warm:
total = self.queryset.count() * len(self.size_key_list) for a, instance in enumerate(self.queryset, start=1): for b, size_key in enumerate(self.size_key_list, start=1):

Since we are iterating on the queryset, there's not need to use .count on the previous line. So could be replaced by:
total = len(self.queryset) * len(self.size_key_list) for a, instance in enumerate(self.queryset, start=1):

Also, and since the doc recommends it this way:
person_img_warmer = VersatileImageFieldWarmer( instance_or_queryset=instance, rendition_key_set='person_headshot', image_attr='headshot' )

if we pass an instance, it's transformed to a queryset by doing:
if isinstance(instance_or_queryset, Model): queryset = instance_or_queryset.__class__._default_manager.filter( pk=instance_or_queryset.pk )
making a query to the db again. I guess it can be easily replaced with:
if isinstance(instance_or_queryset, Model): queryset =[instance_or_queryset]
since we won't do queryset.count().

Unless I miss something, happy to open a PR with the changes

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions