Skip to content

Commit

Permalink
sitemap: store only urls to cache
Browse files Browse the repository at this point in the history
  • Loading branch information
yashlamba authored and slint committed Nov 20, 2023
1 parent deff58d commit 159e740
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
7 changes: 3 additions & 4 deletions site/zenodo_rdm/sitemap/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,9 @@ def update_sitemap_cache(urls=None, max_url_count=None):
sitemap.clear_cache()
while urls_slice:
page_n += 1
page = render_template(
"zenodo_sitemap/sitemap.xml", urlset=filter(None, urls_slice)
)
sitemap.set_cache(f"sitemap:{page_n}", page)
sitemap.set_cache(
f"sitemap:{page_n}", urls_slice
) # Cache only the URLs and render the page on request
urls_slice = list(itertools.islice(urls, max_url_count))

urlset = [
Expand Down
4 changes: 3 additions & 1 deletion site/zenodo_rdm/sitemap/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

"""Redirects for legacy URLs."""

from flask import Blueprint, abort, current_app
from flask import Blueprint, abort, current_app, render_template
from invenio_cache import current_cache

blueprint = Blueprint(
Expand All @@ -21,6 +21,8 @@

def _get_cached_or_404(page):
data = current_cache.get("sitemap:" + str(page))
if page != 0:
data = render_template("zenodo_sitemap/sitemap.xml", urlset=filter(None, data))
if data:
return current_app.response_class(data, mimetype="text/xml")
else:
Expand Down

0 comments on commit 159e740

Please sign in to comment.