Skip to content

Commit 50510a5

Browse files
Merge pull request #151 from developmentseed/patch/fix-previous-offset
fix `prev` offset
2 parents 3a7ed4f + 8de32f5 commit 50510a5

File tree

3 files changed

+34
-2
lines changed

3 files changed

+34
-2
lines changed

CHANGES.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/).
66

77
Note: Minor version `0.X.0` update might break the API, It's recommended to pin `tipg` to minor version: `tipg>=0.1,<0.2`
88

9+
## [0.5.5] - 2023-12-19
10+
11+
- Fix `prev` offset value
12+
913
## [0.5.4] - 2023-12-19
1014

1115
- Fix decimal error for streaming responses (author @RemcoMeeuwissen, https://github.com/developmentseed/tipg/pull/148)
@@ -247,7 +251,8 @@ Note: Minor version `0.X.0` update might break the API, It's recommended to pin
247251

248252
- Initial release
249253

250-
[unreleased]: https://github.com/developmentseed/tipg/compare/0.5.4...HEAD
254+
[unreleased]: https://github.com/developmentseed/tipg/compare/0.5.5...HEAD
255+
[0.5.5]: https://github.com/developmentseed/tipg/compare/0.5.4...0.5.5
251256
[0.5.4]: https://github.com/developmentseed/tipg/compare/0.5.3...0.5.4
252257
[0.5.3]: https://github.com/developmentseed/tipg/compare/0.5.2...0.5.3
253258
[0.5.2]: https://github.com/developmentseed/tipg/compare/0.5.1...0.5.2

tests/routes/test_items.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,31 @@ def test_items_limit_and_offset(app):
8484
response = app.get("/collections/public.landsat_wrs/items?limit=10001")
8585
assert response.status_code == 422
8686

87+
response = app.get("/collections/public.landsat_wrs/items?limit=100&offset=100")
88+
assert response.status_code == 200
89+
assert response.headers["content-type"] == "application/geo+json"
90+
body = response.json()
91+
assert len(body["features"]) == 100
92+
assert body["numberMatched"] == 16269
93+
assert body["numberReturned"] == 100
94+
# Next
95+
assert "limit=100&offset=200" in body["links"][2]["href"]
96+
# Prev
97+
assert "limit=100&offset=0" in body["links"][3]["href"]
98+
99+
# offset + limit overflow the total number of items
100+
response = app.get("/collections/public.landsat_wrs/items?limit=100&offset=16200")
101+
assert response.status_code == 200
102+
assert response.headers["content-type"] == "application/geo+json"
103+
body = response.json()
104+
assert len(body["features"]) == 69
105+
assert body["numberMatched"] == 16269
106+
assert body["numberReturned"] == 69
107+
# No NEXT link
108+
assert "next" not in [link["rel"] for link in body["links"]]
109+
# Prev
110+
assert "limit=100&offset=16100" in body["links"][2]["href"]
111+
87112

88113
def test_items_bbox(app):
89114
"""Test /items endpoint with bbox options."""

tipg/collections.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -742,7 +742,9 @@ async def features(
742742
function_parameters: Optional[Dict[str, str]] = None,
743743
) -> ItemList:
744744
"""Build and run Pg query."""
745+
limit = limit or features_settings.default_features_limit
745746
offset = offset or 0
747+
746748
function_parameters = function_parameters or {}
747749

748750
if geom and geom.lower() != "none" and not self.get_geometry_column(geom):
@@ -792,7 +794,7 @@ async def features(
792794
items=features,
793795
matched=matched,
794796
next=offset + returned if matched - returned > offset else None,
795-
prev=max(offset - returned, 0) if offset else None,
797+
prev=max(offset - limit, 0) if offset else None,
796798
)
797799

798800
async def get_tile(

0 commit comments

Comments
 (0)