[Django] #32850: Sitemap.items() gets called several times: Fix or document?

6 views
Skip to first unread message

Django

unread,
Jun 15, 2021, 9:27:50 AM6/15/21
to django-...@googlegroups.com
#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 | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
------------------------------------------+------------------------
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>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Jun 15, 2021, 9:28:19 AM6/15/21
to django-...@googlegroups.com
#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 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:

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>

Django

unread,
Jun 15, 2021, 9:28:44 AM6/15/21
to django-...@googlegroups.com
#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 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>

Django

unread,
Jun 15, 2021, 9:29:41 AM6/15/21
to django-...@googlegroups.com
#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.


>
> 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>

Django

unread,
Jun 15, 2021, 9:31:24 AM6/15/21
to django-...@googlegroups.com
#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
> 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>

Django

unread,
Jun 15, 2021, 10:11:03 AM6/15/21
to django-...@googlegroups.com
#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
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>

Django

unread,
Jun 15, 2021, 10:12:20 AM6/15/21
to django-...@googlegroups.com
#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

unread,
Jun 16, 2021, 4:40:23 AM6/16/21
to django-...@googlegroups.com
#32850: Sitemap.items() gets called several times: Fix or document?
--------------------------------------+------------------------------------

Reporter: Thomas Güttler | Owner: nobody
Type: Cleanup/optimization | Status: new
Component: Documentation | Version: 3.2
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted

Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
--------------------------------------+------------------------------------
Changes (by Carlton Gibson):

* 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>

Django

unread,
Jun 30, 2021, 7:30:41 AM6/30/21
to django-...@googlegroups.com
#32850: Sitemap.items() gets called several times: Fix or document?
--------------------------------------+------------------------------------

Reporter: Thomas Güttler | Owner: nobody
Type: Cleanup/optimization | Status: new
Component: Documentation | Version: 3.2
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
--------------------------------------+------------------------------------
Changes (by Mariusz Felisiak):

* has_patch: 0 => 1


Comment:

[https://github.com/django/django/pull/14564 PR]

--
Ticket URL: <https://code.djangoproject.com/ticket/32850#comment:8>

Django

unread,
Jun 30, 2021, 2:41:54 PM6/30/21
to django-...@googlegroups.com
#32850: Sitemap.items() gets called several times: Fix or document?
-------------------------------------+-------------------------------------
Reporter: Thomas Güttler | Owner: Thomas
Type: | Güttler
Cleanup/optimization | Status: assigned

Component: Documentation | Version: 3.2
Severity: Normal | Resolution:
Keywords: | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Mariusz Felisiak):

* owner: nobody => Thomas Güttler
* status: new => assigned
* stage: Accepted => Ready for checkin


--
Ticket URL: <https://code.djangoproject.com/ticket/32850#comment:9>

Django

unread,
Jun 30, 2021, 3:02:18 PM6/30/21
to django-...@googlegroups.com
#32850: Sitemap.items() gets called several times: Fix or document?
-------------------------------------+-------------------------------------
Reporter: Thomas Güttler | Owner: Thomas
Type: | Güttler
Cleanup/optimization | Status: closed
Component: Documentation | Version: 3.2
Severity: Normal | Resolution: fixed

Keywords: | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Mariusz Felisiak <felisiak.mariusz@…>):

* 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>

Django

unread,
Jun 30, 2021, 3:02:34 PM6/30/21
to django-...@googlegroups.com
#32850: Sitemap.items() gets called several times: Fix or document?
-------------------------------------+-------------------------------------
Reporter: Thomas Güttler | Owner: Thomas
Type: | Güttler
Cleanup/optimization | Status: closed
Component: Documentation | Version: 3.2
Severity: Normal | Resolution: fixed
Keywords: | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

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>

Reply all
Reply to author
Forward
0 new messages