Skip to content
This repository has been archived by the owner on Jan 25, 2022. It is now read-only.

Commit

Permalink
Merge pull request #209 from Kinto/bypass-database-on-since-redirect
Browse files Browse the repository at this point in the history
Bypass database on _since redirect
  • Loading branch information
leplatrem committed Sep 28, 2020
2 parents bdf273f + e03bae7 commit ca7c915
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 12 deletions.
4 changes: 3 additions & 1 deletion CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ Changelog
3.2.0 (unreleased)
------------------

- Nothing changed yet.
**Bug fixes**

- Bypass storage when redirecting on old ``_since``


3.1.0 (2020-09-22)
Expand Down
25 changes: 14 additions & 11 deletions kinto_changes/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,16 +90,14 @@ class Changes(resource.Resource):
schema = ChangesSchema

def __init__(self, request, context=None):
super(Changes, self).__init__(request, context)
# Bypass call to storage if _since is too old.
_handle_old_since_redirect(request)
# Inject custom model.
self.model = ChangesModel(request)

@property
def timestamp(self):
return self.model.timestamp()
super(Changes, self).__init__(request, context)

def plural_get(self):
result = super().plural_get()
_handle_old_since_redirect(self.request)
_handle_cache_expires(self.request, MONITOR_BUCKET, CHANGES_COLLECTION)
return result

Expand Down Expand Up @@ -135,8 +133,13 @@ def _handle_old_since_redirect(request):
See https://bugzilla.mozilla.org/show_bug.cgi?id=1529685
and https://bugzilla.mozilla.org/show_bug.cgi?id=1665319#c2
"""
qs_since = request.validated["querystring"].get("_since")
if qs_since is None:
try:
# request.validated is not populated yet (resource was not instantiated yet,
# we want to bypass storage).
qs_since_str = request.GET.get("_since", "")
qs_since = int(qs_since_str.strip('"'))
except ValueError:
# Will fail later during resource querystring validation.
return

settings = request.registry.settings
Expand Down Expand Up @@ -240,13 +243,13 @@ def get_changeset(request):
include_deleted = True

if (bid, cid) == (MONITOR_BUCKET, CHANGES_COLLECTION):
model = ChangesModel(request)
# Redirect old since, on monitor/changes only.
_handle_old_since_redirect(request)

model = ChangesModel(request)
metadata = {}
timestamp = model.timestamp()
changes = model.get_objects(filters=filters, include_deleted=include_deleted)
# Redirect old since, on monitor/changes only.
_handle_old_since_redirect(request)

else:
bucket_uri = instance_uri(request, "bucket", id=bid)
Expand Down

0 comments on commit ca7c915

Please sign in to comment.