#32850: Sitemap.items() gets called several times: Fix or document?
--------------------------------+--------------------------------------
     Reporter:  Thomas Güttler  |                    Owner:  nobody
         Type:  Uncategorized   |                   Status:  new
    Component:  Uncategorized   |                  Version:  3.2
     Severity:  Normal          |               Resolution:
     Keywords:                  |             Triage Stage:  Unreviewed
    Has patch:  0               |      Needs documentation:  0
  Needs tests:  0               |  Patch needs improvement:  0
Easy pickings:  0               |                    UI/UX:  0
--------------------------------+--------------------------------------
Description changed by Thomas Güttler:

Old description:

> The
> [https://docs.djangoproject.com/en/3.2/ref/contrib/sitemaps/#django.contrib.sitemaps.Sitemap.items
> Sitemap.items()] method might get called several times (if you generate
> several pages in batch)
>
> This is confusing and might waste computation resources.
>
> {{{
>     def _urls(self, page, protocol, domain):
>         urls = []
>         latest_lastmod = None
>         all_items_lastmod = True  # track if all items have a lastmod
>         for item in self.paginator.page(page).object_list:
>             loc = "%s://%s%s" % (protocol, domain, self.__get('location',
> item))
>             ....
> }}}
>
> {{{
>     @property
>     def paginator(self):
>         return paginator.Paginator(self._items(), self.limit)
>
> }}}
>
> I see two options now:
>
> Option1: Document this behaviour.
>
> Option2: make paginator a cached_property.

New description:

 The
 
[https://docs.djangoproject.com/en/3.2/ref/contrib/sitemaps/#django.contrib.sitemaps.Sitemap.items
 Sitemap.items()] method might get called several times (if you generate
 several pages in batch)

 This is confusing and might waste computation resources.

 {{{
     def _urls(self, page, protocol, domain):
         urls = []
         latest_lastmod = None
         all_items_lastmod = True  # track if all items have a lastmod
         paginator_page = self.paginator.page(page)
         for item in paginator_page.object_list:
             loc = f'{protocol}://{domain}{self._location(item)}'
             ....
 }}}

 {{{
     @property
     def paginator(self):
         return paginator.Paginator(self._items(), self.limit)

 }}}

 I see two options now:

 Option1: Document this behaviour.

 Option2: make paginator a cached_property.

--

-- 
Ticket URL: <https://code.djangoproject.com/ticket/32850#comment:6>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/065.bafdbdd96941a746bbc30ba3f39cc4b2%40djangoproject.com.

Reply via email to