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))
....
```
I see two options now:
Option1: Document this behaviour.
Option2: make paginator a cached_property.
--
Ticket URL: <https://code.djangoproject.com/ticket/32850>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
Old description:
> The
> [https://docs.djangoproject.com/en/3.2/ref/contrib/sitemaps/#django.contrib.sitemaps.Sitemap.items
> Sitemap.items()] method gets called several times.
>
> 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))
> ....
> ```
>
> 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 gets called several times.
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))
....
}}}
I see two options now:
Option1: Document this behaviour.
Option2: make paginator a cached_property.
--
--
Ticket URL: <https://code.djangoproject.com/ticket/32850#comment:1>
Old description:
> The
> [https://docs.djangoproject.com/en/3.2/ref/contrib/sitemaps/#django.contrib.sitemaps.Sitemap.items
> Sitemap.items()] method gets called several times.
>
> 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))
> ....
> }}}
>
> 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.
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))
....
}}}
I see two options now:
Option1: Document this behaviour.
Option2: make paginator a cached_property.
--
--
Ticket URL: <https://code.djangoproject.com/ticket/32850#comment:2>
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.
>
> 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))
> ....
> }}}
>
> 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
them in batch, not during the http-request).
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))
....
}}}
I see two options now:
Option1: Document this behaviour.
Option2: make paginator a cached_property.
--
--
Ticket URL: <https://code.djangoproject.com/ticket/32850#comment:3>
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
> them in batch, not during the http-request).
>
> 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))
> ....
> }}}
>
> 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
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.
--
--
Ticket URL: <https://code.djangoproject.com/ticket/32850#comment:4>
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
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.
--
--
Ticket URL: <https://code.djangoproject.com/ticket/32850#comment:5>
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>
* type: Uncategorized => Cleanup/optimization
* component: Uncategorized => Documentation
* stage: Unreviewed => Accepted
Comment:
Hi Thomas, thanks.
> The Sitemap.items() method might get called several times (if you
generate several pages in batch)
I don't see this as any different from (e.g.) a paginated `ListView`, i.e.
not really as problematic.
If you wanted to add `paginator` to the reference docs though, with a
comment such as ''You may wish to override as a cached property this if
you are generating multiple sitemap pages in a batch'' (or something) I
guess that wouldn't hurt.
--
Ticket URL: <https://code.djangoproject.com/ticket/32850#comment:7>
* has_patch: 0 => 1
Comment:
[https://github.com/django/django/pull/14564 PR]
--
Ticket URL: <https://code.djangoproject.com/ticket/32850#comment:8>
* owner: nobody => Thomas Güttler
* status: new => assigned
* stage: Accepted => Ready for checkin
--
Ticket URL: <https://code.djangoproject.com/ticket/32850#comment:9>
* status: assigned => closed
* resolution: => fixed
Comment:
In [changeset:"775f7506d7fbabf79d8bdec4ccf039ce2870fe70" 775f7506]:
{{{
#!CommitTicketReference repository=""
revision="775f7506d7fbabf79d8bdec4ccf039ce2870fe70"
Fixed #32850 -- Doc'd Sitemap.paginator.
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/32850#comment:10>
Comment (by Mariusz Felisiak <felisiak.mariusz@…>):
In [changeset:"aaef4111ac880b530ce85557dc614f581ae8f3a9" aaef4111]:
{{{
#!CommitTicketReference repository=""
revision="aaef4111ac880b530ce85557dc614f581ae8f3a9"
[3.2.x] Fixed #32850 -- Doc'd Sitemap.paginator.
Backport of 775f7506d7fbabf79d8bdec4ccf039ce2870fe70 from main
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/32850#comment:11>