Skip to content

Commit

Permalink
Fix pagination in the history API
Browse files Browse the repository at this point in the history
  • Loading branch information
Donnype committed Jan 22, 2025
1 parent 59d6eb7 commit 023d4b5
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
2 changes: 1 addition & 1 deletion octopoes/octopoes/xtdb/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ def get_entity_history(
if indices:
return [tx for i, tx in enumerate(transactions) if i in indices or i - len(transactions) in indices]

return transactions[offset:limit]
return transactions[offset:None if limit is None else limit + offset]

def query(self, query: str | Query, valid_time: datetime | None = None) -> list[list[Any]]:
if valid_time is None:
Expand Down
6 changes: 6 additions & 0 deletions octopoes/tests/integration/test_api_connector.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,12 @@ def test_history(octopoes_api_connector: OctopoesAPIConnector):
assert len(octopoes_api_connector.get_history(network.reference, offset=1)) == 2
assert len(octopoes_api_connector.get_history(network.reference, limit=2)) == 2

# Test that moving the offset with 1 shifts the result set
assert (octopoes_api_connector.get_history(network.reference, offset=0, limit=2)[1] ==
octopoes_api_connector.get_history(network.reference, offset=1, limit=2)[0])
assert len(octopoes_api_connector.get_history(network.reference, offset=2, limit=10)) == 1
assert len(octopoes_api_connector.get_history(network.reference, offset=2, limit=1)) == 1

first_and_last = octopoes_api_connector.get_history(network.reference, has_doc=True, indices=[0, -1])
assert len(first_and_last) == 2
assert first_and_last[0].valid_time == first_seen
Expand Down

0 comments on commit 023d4b5

Please sign in to comment.