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

Remove use of etags and lastmod data from sitemaps #15225

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
20 changes: 20 additions & 0 deletions bedrock/sitemaps/migrations/0002_remove_sitemapurl_lastmod.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at https://mozilla.org/MPL/2.0/.

# Generated by Django 4.2.16 on 2024-09-27 17:51

from django.db import migrations


class Migration(migrations.Migration):
dependencies = [
("sitemaps", "0001_initial"),
]

operations = [
migrations.RemoveField(
model_name="sitemapurl",
name="lastmod",
),
]
19 changes: 3 additions & 16 deletions bedrock/sitemaps/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,33 +12,21 @@


def load_sitemaps_data():
with SITEMAPS_DATA.joinpath("etags.json").open() as fh:
etags = json.load(fh)

with SITEMAPS_DATA.joinpath("sitemap.json").open() as fh:
sitemap = json.load(fh)

return sitemap, etags
return sitemap


def get_sitemap_objs():
objs = []
sitemap, etags = load_sitemaps_data()
sitemap = load_sitemaps_data()
for url, locales in sitemap.items():
if not locales:
locales = [NO_LOCALE]

for locale in locales:
if locale == NO_LOCALE:
full_url = f"{settings.CANONICAL_URL}{url}"
else:
full_url = f"{settings.CANONICAL_URL}/{locale}{url}"

kwargs = {"path": url, "locale": locale}
etag = etags.get(full_url)
if etag:
kwargs["lastmod"] = etag["date"]
objs.append(SitemapURL(**kwargs))
objs.append(SitemapURL(path=url, locale=locale))

return objs

Expand All @@ -59,7 +47,6 @@ def all_locales(self):
class SitemapURL(models.Model):
path = models.CharField(max_length=200)
locale = models.CharField(max_length=5)
lastmod = models.CharField(max_length=40, blank=True)

objects = SitemapURLManager()

Expand Down
12 changes: 4 additions & 8 deletions bedrock/sitemaps/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@
class TestSitemapView(TestCase):
def setUp(self):
data = [
{"path": "/firefox/all/", "locale": "de", "lastmod": "2020-07-01T21:07:08.730133+00:00"},
{"path": "/firefox/", "locale": "de", "lastmod": "2020-07-01T21:07:08.730133+00:00"},
{"path": "/firefox/all/", "locale": "de"},
{"path": "/firefox/", "locale": "de"},
{
"path": "/privacy/",
"locale": "fr",
},
{"path": "/firefox/", "locale": "fr", "lastmod": "2020-07-01T21:07:08.730133+00:00"},
{"path": "/keymaster/gatekeeper/there.is.only.xul", "locale": NO_LOCALE, "lastmod": "2020-07-01T21:07:08.730133+00:00"},
{"path": "/firefox/", "locale": "fr"},
{"path": "/keymaster/gatekeeper/there.is.only.xul", "locale": NO_LOCALE},
{
"path": "/locales/",
"locale": NO_LOCALE,
Expand Down Expand Up @@ -52,7 +52,6 @@ def test_none(self):
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:xhtml="http://www.w3.org/1999/xhtml">
<url>
<loc>https://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul</loc>
<lastmod>2020-07-01T21:07:08.730133+00:00</lastmod>
</url>
<url>
<loc>https://www.mozilla.org/locales/</loc>
Expand All @@ -69,11 +68,9 @@ def test_locales(self):
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:xhtml="http://www.w3.org/1999/xhtml">
<url>
<loc>https://www.mozilla.org/de/firefox/</loc>
<lastmod>2020-07-01T21:07:08.730133+00:00</lastmod>
</url>
<url>
<loc>https://www.mozilla.org/de/firefox/all/</loc>
<lastmod>2020-07-01T21:07:08.730133+00:00</lastmod>
</url>
</urlset>"""
)
Expand All @@ -86,7 +83,6 @@ def test_locales(self):
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:xhtml="http://www.w3.org/1999/xhtml">
<url>
<loc>https://www.mozilla.org/fr/firefox/</loc>
<lastmod>2020-07-01T21:07:08.730133+00:00</lastmod>
</url>
<url>
<loc>https://www.mozilla.org/fr/privacy/</loc>
Expand Down