Skip to content

Add search API#95

Draft
alexjg wants to merge 1 commit intomainfrom
query
Draft

Add search API#95
alexjg wants to merge 1 commit intomainfrom
query

Conversation

@alexjg
Copy link
Copy Markdown
Owner

@alexjg alexjg commented Apr 28, 2026

Problem: the current Repo::find API is timing sensitive. If the returned future completes with None then there's no way to hear about changes which cause the document to become available (such as a peer who has the document connecting late). This forces applications who want to be oblivious to the order in which network events occur to poll Repo::find.

Solution: Introduce a Repo::search API, which returns a query state representing the current knowledge of the state of the document, plus a stream of future updates. When the document is found the stream returns an item which has the DocHandle in it. This allows applications to listen to the search stream indefinitely.

Introducing the "search" API also significantly simplified the internal logic of the document actor as it no longer needs to track pending dialers - the logic of "a document is unavailable if there are no pending dialers and no connected peers have it" can now live in the find() call.

Problem: the current Repo::find API is timing sensitive. If the returned
future completes with `None` then there's no way to hear about changes
which cause the document to become available (such as a peer who has the
document connecting late). This forces applications who want to be
oblivious to the order in which network events occur to poll
`Repo::find`. 

Solution: Introduce a `Repo::search` API, which returns a query state
representing the current knowledge of the state of the document, plus a
stream of future updates. When the document is found the stream returns
an item which has the `DocHandle` in it. This allows applications to
listen to the search stream indefinitely.

Introducing the "search" API also significantly simplified the internal
logic of the document actor as it no longer needs to track pending
dialers - the logic of "a document is unavailable if there are no
pending dialers and no connected peers have it" can now live in the
`find()` call.
@alexjg
Copy link
Copy Markdown
Owner Author

alexjg commented May 8, 2026

@shikokuchuo this is the new search API I was talking about.

@shikokuchuo
Copy link
Copy Markdown
Contributor

Likely won't need Repo::search directly as samod is only used on the server side. But to the extent that Repo::find becomes a thin wrapper around it probably will benefit us in the long run in preventing races, especially if we start using peering.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants