Skip to content

Commit

Permalink
Add last-serial to the simple index root (pypi#12134)
Browse files Browse the repository at this point in the history
  • Loading branch information
pfmoore authored Aug 30, 2022
1 parent 6b82264 commit 050fa1b
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
10 changes: 8 additions & 2 deletions tests/unit/api/test_simple.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,10 @@ def test_with_results_no_serial(self, db_request, content_type, renderer_overrid
]
assert simple.simple_index(db_request) == {
"meta": {"_last-serial": 0, "api-version": "1.0"},
"projects": [{"name": x[0]} for x in sorted(projects, key=lambda x: x[1])],
"projects": [
{"name": x[0], "_last-serial": 0}
for x in sorted(projects, key=lambda x: x[1])
],
}
assert db_request.response.headers["X-PyPI-Last-Serial"] == "0"
assert db_request.response.content_type == content_type
Expand All @@ -145,7 +148,10 @@ def test_with_results_with_serial(

assert simple.simple_index(db_request) == {
"meta": {"_last-serial": je.id, "api-version": "1.0"},
"projects": [{"name": x[0]} for x in sorted(projects, key=lambda x: x[1])],
"projects": [
{"name": x[0], "_last-serial": 0}
for x in sorted(projects, key=lambda x: x[1])
],
}
assert db_request.response.headers["X-PyPI-Last-Serial"] == str(je.id)
assert db_request.response.content_type == content_type
Expand Down
4 changes: 2 additions & 2 deletions warehouse/packaging/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,14 @@
def _simple_index(request, serial):
# Fetch the name and normalized name for all of our projects
projects = (
request.db.query(Project.name, Project.normalized_name)
request.db.query(Project.name, Project.normalized_name, Project.last_serial)
.order_by(Project.normalized_name)
.all()
)

return {
"meta": {"api-version": API_VERSION, "_last-serial": serial},
"projects": [{"name": p.name} for p in projects],
"projects": [{"name": p.name, "_last-serial": p.last_serial} for p in projects],
}


Expand Down

0 comments on commit 050fa1b

Please sign in to comment.