Branch: refs/heads/master Author: Enrico Tröger enrico.troeger@uvena.de Committer: Enrico Tröger enrico.troeger@uvena.de Date: Sun, 14 Jul 2019 21:22:35 UTC Commit: df25512536edcb8f182b878d6bd7e4a0b6b7c918 https://github.com/geany/www.geany.org/commit/df25512536edcb8f182b878d6bd7e4...
Log Message: ----------- Further delay Site lookup from registration to sitemap generation
aa4dae2 was not enough to prevent Site lookups on database migration. So instead of resolving the Site objects at registration time for Sitemaps, delay the lookup to the generation time.
Modified Paths: -------------- geany/sitemaps.py
Modified: geany/sitemaps.py 38 lines changed, 22 insertions(+), 16 deletions(-) =================================================================== @@ -153,12 +153,10 @@ class SitemapRegistry: def __init__(self): self._sitemap_generators = list() self._static_items = None + self._site = None
# ---------------------------------------------------------------------- def add(self, generator_class, url_patterns, site_domain=None, exclude_views=None): - if site_domain is None: - site = Site.objects.get(id=settings.SITE_ID) - site_domain = site.domain sitemap_generator_item = (generator_class, url_patterns, site_domain, exclude_views) self._sitemap_generators.append(sitemap_generator_item)
@@ -177,27 +175,35 @@ def get_all_items(self):
# ---------------------------------------------------------------------- def _get_static_items(self): - static_items = list() + return self._get_items('get_static_items') + + # ---------------------------------------------------------------------- + def _get_items(self, item_generator_name): + items = list() for generator_class, url_patterns, site_domain, exclude_views in self._sitemap_generators: + site_domain = self._get_site_domain_or_default(site_domain) generator = generator_class( site_domain, url_patterns, exclude_views=exclude_views) - items = generator.get_static_items() - static_items.extend(items) - return static_items + item_generator = getattr(generator, item_generator_name) + generated_items = item_generator() + items.extend(generated_items) + return items + + # ---------------------------------------------------------------------- + def _get_site_domain_or_default(self, site_domain): + if site_domain is None: + if self._site is None: + self._site = Site.objects.get(id=settings.SITE_ID) + + site_domain = self._site.domain + + return site_domain
# ---------------------------------------------------------------------- def _get_dynamic_items(self): - dynamic_items = list() - for generator_class, url_patterns, site_domain, exclude_views in self._sitemap_generators: - generator = generator_class( - site_domain, - url_patterns, - exclude_views=exclude_views) - items = generator.get_dynamic_items() - dynamic_items.extend(items) - return dynamic_items + return self._get_items('get_dynamic_items')
sitemap_registry = SitemapRegistry() # pylint: disable=invalid-name
-------------- This E-Mail was brought to you by github_commit_mail.py (Source: https://github.com/geany/infrastructure).