Commit 0186cfff authored by Julien Cristau's avatar Julien Cristau

Fix check for whether /tracker/data/json needs to be recomputed

In commit 49e287d2 "tracker_service:
send a Last-Modified header for /tracker/data/json" I made the
json_timestamp update conditional on whether the data had changed.  That
meant that after a few minutes, we would consider the data to be always
stale, and recompute it every single time, as long as it didn't change.

To fix this, use separate timestamps for "when did we check last"
(json_timestamp) and "when did it change last" (json_last_modified).
parent 8a51bec9
......@@ -137,6 +137,7 @@ class TrackerService(webservice_base_class):
self.db = security_db.DB(db_name)
self.json_data = None # the JSON dump itself
self.json_timestamp = None # timestamp of JSON generation
self.json_last_modified = None
self.register('', self.page_home)
self.register('*', self.page_object)
self.register('redirect/*', self.page_redirect)
......@@ -1452,14 +1453,15 @@ Debian bug number.'''),
# store the JSON dump in memory, and update the generation
# timestamp before returning
new_data = json.dumps(data, separators=(',', ':'))
self.json_timestamp = time.time()
if new_data != self.json_data:
self.json_data = new_data
self.json_timestamp = time.time()
self.json_last_modified = self.json_timestamp
return self.json_data
def page_json(self, path, params, url):
result = BinaryResult(self._get_json(),'application/json')
result.headers['Last-Modified'] = email.utils.formatdate(self.json_timestamp, usegmt=True)
result.headers['Last-Modified'] = email.utils.formatdate(self.json_last_modified, usegmt=True)
return result
def page_debsecan(self, path, params, url):
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment