Skip to content

Commit 9bc4816

Browse files
committed
Implement Last-Modifed header support for rebuilderd
Rebuilderd now supports the Last-Modified header and If-Modified-Since when requesting the rebuilderd package list. This saves us from iterating over all rebuilderd results and fetching the status form the database.
1 parent cc799ff commit 9bc4816

File tree

1 file changed

+18
-2
lines changed

1 file changed

+18
-2
lines changed

devel/management/commands/read_rebuilderd_status.py

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
import requests
1818

19+
from django.core.cache import cache
1920
from django.core.mail import send_mail
2021
from django.conf import settings
2122
from django.core.management.base import BaseCommand
@@ -53,7 +54,8 @@ def handle(self, *args, **options):
5354

5455
was_repro = import_rebuilderd_status(url)
5556

56-
send_repro_emails(was_repro)
57+
if was_repro:
58+
send_repro_emails(was_repro)
5759

5860

5961
def send_repro_emails(was_repro):
@@ -80,8 +82,22 @@ def send_repro_emails(was_repro):
8082
def import_rebuilderd_status(url):
8183
statuses = []
8284
was_repro = []
85+
headers = {}
86+
87+
last_modified = cache.get('rebuilderd:last-modified')
88+
if last_modified:
89+
logger.debug('Setting If-Modified-Since header')
90+
headers = {'If-Modified-Since': last_modified}
91+
92+
req = requests.get(url, headers=headers)
93+
if req.status_code == 304:
94+
logger.debug('The rebuilderd data has not been updated since we last checked it')
95+
return was_repro
96+
97+
last_modified = req.headers.get('last-modified')
98+
if last_modified:
99+
cache.set('rebuilderd:last-modified', last_modified, 86400)
83100

84-
req = requests.get(url)
85101
data = req.json()
86102

87103
# Lookup dictionary to reduce SQL queries.

0 commit comments

Comments
 (0)