Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sitemap: store only urls to cache #658

Merged
merged 1 commit into from
Nov 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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