Sitemap.items() gets called several times: Fix or document?
The 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.
Change History
(11)
Description: |
modified (diff)
|
Description: |
modified (diff)
|
Description: |
modified (diff)
|
Description: |
modified (diff)
|
Description: |
modified (diff)
|
Description: |
modified (diff)
|
Component: |
Uncategorized → Documentation
|
Triage Stage: |
Unreviewed → Accepted
|
Type: |
Uncategorized → Cleanup/optimization
|
Owner: |
changed from nobody to Thomas Güttler
|
Status: |
new → assigned
|
Triage Stage: |
Accepted → Ready for checkin
|
Resolution: |
→ fixed
|
Status: |
assigned → closed
|
Hi Thomas, thanks.
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.