Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: use base64 encoded JSON string of sort keys as pagination token #323

Merged
merged 2 commits into from
Dec 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).

## [Unreleased]
### Changed
- Use base64 encoded JSON string of sort keys as pagination token instead of comma-separated string [#323](https://github.com/stac-utils/stac-fastapi-elasticsearch-opensearch/pull/323)

## [v3.2.1] - 2024-11-14

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""Database logic."""

import asyncio
import json
import logging
import os
from base64 import urlsafe_b64decode, urlsafe_b64encode
Expand Down Expand Up @@ -660,7 +661,7 @@ async def execute_search(
search_after = None

if token:
search_after = urlsafe_b64decode(token.encode()).decode().split(",")
search_after = json.loads(urlsafe_b64decode(token).decode())

query = search.query.to_dict() if search.query else None

Expand Down Expand Up @@ -700,9 +701,7 @@ async def execute_search(
next_token = None
if len(hits) > limit and limit < max_result_window:
if hits and (sort_array := hits[limit - 1].get("sort")):
next_token = urlsafe_b64encode(
",".join([str(x) for x in sort_array]).encode()
).decode()
next_token = urlsafe_b64encode(json.dumps(sort_array).encode()).decode()

matched = (
es_response["hits"]["total"]["value"]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""Database logic."""

import asyncio
import json
import logging
import os
from base64 import urlsafe_b64decode, urlsafe_b64encode
Expand Down Expand Up @@ -692,7 +693,7 @@ async def execute_search(
search_after = None

if token:
search_after = urlsafe_b64decode(token.encode()).decode().split(",")
search_after = json.loads(urlsafe_b64decode(token).decode())
if search_after:
search_body["search_after"] = search_after

Expand Down Expand Up @@ -732,9 +733,7 @@ async def execute_search(
next_token = None
if len(hits) > limit and limit < max_result_window:
if hits and (sort_array := hits[limit - 1].get("sort")):
next_token = urlsafe_b64encode(
",".join([str(x) for x in sort_array]).encode()
).decode()
next_token = urlsafe_b64encode(json.dumps(sort_array).encode()).decode()

matched = (
es_response["hits"]["total"]["value"]
Expand Down
Loading