#32850 closed Cleanup/optimization (fixed)
Sitemap.items() gets called several times: Fix or document?
Description (last modified by ) ¶
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)
comment:1 by , 4 years ago
Description: | modified (diff) |
---|
comment:2 by , 4 years ago
Description: | modified (diff) |
---|
comment:3 by , 4 years ago
Description: | modified (diff) |
---|
comment:4 by , 4 years ago
Description: | modified (diff) |
---|
comment:5 by , 4 years ago
Description: | modified (diff) |
---|
comment:6 by , 4 years ago
Description: | modified (diff) |
---|
comment:7 by , 4 years ago
Component: | Uncategorized → Documentation |
---|---|
Triage Stage: | Unreviewed → Accepted |
Type: | Uncategorized → Cleanup/optimization |
comment:9 by , 4 years ago
Owner: | changed from | to
---|---|
Status: | new → assigned |
Triage Stage: | Accepted → Ready for checkin |
Note:
See TracTickets
for help on using tickets.
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.