def _cached_items()

in src/olympia/amo/sitemap.py [0:0]


    def _cached_items(self):
        current_app = self._current_app
        addon_q = Q(
            addons___current_version__isnull=False,
            addons___current_version__apps__application=current_app.id,
            addons__disabled_by_user=False,
            addons__status__in=amo.APPROVED_STATUSES,
            addonuser__listed=True,
            addonuser__role__in=(amo.AUTHOR_ROLE_DEV, amo.AUTHOR_ROLE_OWNER),
        )
        # android is currently limited to a small number of recommended addons, so get
        # the list of those and filter further
        if current_app == amo.ANDROID:
            promoted_addon_ids = get_android_promoted_addons()
            addon_q = addon_q & Q(addons__id__in=promoted_addon_ids)

        users = (
            UserProfile.objects.filter(has_full_profile=True, deleted=False)
            .annotate(
                theme_count=Count(
                    'addons', filter=Q(addon_q, addons__type=amo.ADDON_STATICTHEME)
                )
            )
            .annotate(
                extension_count=Count(
                    'addons', filter=Q(addon_q, addons__type=amo.ADDON_EXTENSION)
                )
            )
            .annotate(addons_updated=Max('addons__last_updated', filter=addon_q))
            .order_by('-addons_updated', '-modified')
            .values_list(
                'addons_updated', 'id', 'extension_count', 'theme_count', named=True
            )
            .iterator()
        )
        items = []
        for user in users:
            if not user.extension_count and not user.theme_count:
                # some users have an empty page for various reasons, no need to include
                continue
            extension_pages_needed = math.ceil(
                (user.extension_count or 1) / EXTENSIONS_BY_AUTHORS_PAGE_SIZE
            )
            theme_pages_needed = math.ceil(
                (user.theme_count or 1) / THEMES_BY_AUTHORS_PAGE_SIZE
            )
            items.extend(
                self.item_tuple(
                    user.addons_updated,
                    reverse('users.profile', args=[user.id]),
                    ext_page,
                    1,
                )
                for ext_page in range(1, extension_pages_needed + 1)
            )
            # start themes at 2 because we don't want (1, 1) twice
            items.extend(
                self.item_tuple(
                    user.addons_updated,
                    reverse('users.profile', args=[user.id]),
                    1,
                    theme_page,
                )
                for theme_page in range(2, theme_pages_needed + 1)
            )
        return items