Skip to content

Commit

Permalink
treat empty-string cursors the same as nonexistent
Browse files Browse the repository at this point in the history
  • Loading branch information
DavidBuchanan314 committed Jan 10, 2025
1 parent c649185 commit cfaa18f
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 6 deletions.
4 changes: 3 additions & 1 deletion src/millipds/atproto_repo.py
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,9 @@ async def repo_list_records(request: web.Request):
if limit < 1 or limit > 100:
raise web.HTTPBadRequest(text="limit out of range")
reverse = request.query.get("reverse") == "true"
cursor = request.query.get("cursor", "" if reverse else "\xff")
cursor = request.query.get("cursor", "")
if not reverse and not cursor:
cursor = "\xff" # compares greater than all valid rkeys
did_or_handle = request.query["repo"]
collection = request.query["collection"]
records = []
Expand Down
6 changes: 3 additions & 3 deletions src/millipds/atproto_sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ async def sync_list_blobs(request: web.Request):
limit = int(request.query.get("limit", 500))
if limit < 1 or limit > 1000:
raise web.HTTPBadRequest(text="limit out of range")
cursor = int(request.query.get("cursor", 0))
cursor = int(request.query.get("cursor") or 0)

cids = []
for id_, cid in get_db(request).con.execute(
Expand Down Expand Up @@ -246,9 +246,9 @@ async def sync_subscribe_repos(request: web.Request):
await ws.prepare(request) # TODO: should this be outside of try?

last_sent_seq = None
if "cursor" in request.query:
if cursor_str := request.query.get("cursor"):
# TODO: try to limit number of concurrent backfillers? (it's more expensive than livetailing)
cursor = int(request.query["cursor"])
cursor = int(cursor_str)
db = get_db(request)
while True:
# we read one at a time to force gaps between reads - could be a perf win to read in small batches
Expand Down
1 change: 1 addition & 0 deletions src/millipds/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ def _init_tables(self):
) STRICT
"""
)
# TODO: index on timestamp for efficient purging of old events.

# repo storage stuff
self.con.execute(
Expand Down
5 changes: 3 additions & 2 deletions tests/integration_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -494,17 +494,18 @@ async def test_deleteSession(s, pds_host):
) as r:
assert r.status != 200


async def test_updateHandle(s, pds_host, auth_headers):
async with s.post(
pds_host + "/xrpc/com.atproto.identity.updateHandle",
headers=auth_headers,
json={ "handle": "juliet.test" },
json={"handle": "juliet.test"},
) as r:
assert r.status == 200

async with s.get(
pds_host + "/xrpc/com.atproto.repo.describeRepo",
params={ "repo": TEST_DID },
params={"repo": TEST_DID},
) as r:
assert r.status == 200
r = await r.json()
Expand Down

0 comments on commit cfaa18f

Please sign in to comment.