Opened 3 years ago

Closed 3 years ago

Last modified 3 years ago

#32850 closed Cleanup/optimization (fixed)

Sitemap.items() gets called several times: Fix or document?

Reported by: Thomas Güttler Owned by: Thomas Güttler
Component: Documentation Version: 3.2
Severity: Normal Keywords:
Cc: Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description (last modified by Thomas Güttler)

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 Thomas Güttler, 3 years ago

Description: modified (diff)

comment:2 by Thomas Güttler, 3 years ago

Description: modified (diff)

comment:3 by Thomas Güttler, 3 years ago

Description: modified (diff)

comment:4 by Thomas Güttler, 3 years ago

Description: modified (diff)

comment:5 by Thomas Güttler, 3 years ago

Description: modified (diff)

comment:6 by Thomas Güttler, 3 years ago

Description: modified (diff)

comment:7 by Carlton Gibson, 3 years ago

Component: UncategorizedDocumentation
Triage Stage: UnreviewedAccepted
Type: UncategorizedCleanup/optimization

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.

comment:8 by Mariusz Felisiak, 3 years ago

Has patch: set

comment:9 by Mariusz Felisiak, 3 years ago

Owner: changed from nobody to Thomas Güttler
Status: newassigned
Triage Stage: AcceptedReady for checkin

comment:10 by Mariusz Felisiak <felisiak.mariusz@…>, 3 years ago

Resolution: fixed
Status: assignedclosed

In 775f7506:

Fixed #32850 -- Doc'd Sitemap.paginator.

comment:11 by Mariusz Felisiak <felisiak.mariusz@…>, 3 years ago

In aaef4111:

[3.2.x] Fixed #32850 -- Doc'd Sitemap.paginator.

Backport of 775f7506d7fbabf79d8bdec4ccf039ce2870fe70 from main

Note: See TracTickets for help on using tickets.
Back to Top