n0-computer / iroh

A toolkit for building distributed applications
https://iroh.computer
Apache License 2.0
2.28k stars 147 forks source link

Add doc query param for ContentStatus, return entry ContentStatus on doc queries #2523

Open b5 opened 1 month ago

b5 commented 1 month ago

We currently attach a ContentStatus struct to Doc InsertRemote events. ContentStatus is a three-state enum of { Missing, Complete, Incomplete }

Feature Request

I'm requesting two new features:

  1. Add a ContentStatus query parameter that will filter the returned Entries from a query. Parameter should accept the following combinations:
    • Any: no filtering, return all entries as we do now
    • Missing: return only blobs that have no data cached locally
    • Missing | Incomplete: return blobs all blobs that are not complete
    • Complete: return only blobs that are complete and local
    • Incomplete: return only blobs that are partially local
    • Complete | Incomplete: return blobs that are not missing
  2. Add a content_status field/accessor to the return value of an Entry, which will always have a value of { Missing, Incomplete, Complete }.

Use Case

I'm building a photo sharing app, where each entry in a document points to a png image. When the document syncs to the device, I'm running a query for all of the latest entries in the document, displaying thumbnails of all photos in a grid view. The grid view is generated with an "all keys merged by latest time stamp" query. The problem at the moment: during initial sync, the query returns numerous keys that we don't currently have the content for. Right now the best iroh offers is to subscribe to events, looking for changes in content_status. This is incomplete at best.

Both features play a useful role: Being able to query for only complete content makes rolling out the initial version of the app easy: listen for any document event, and re-run a query with the ContentStatus: Complete filter, displaying the results (this can also power "show downloaded content only"-type features). Then later for a display that is less jumpy, we can relax the query to return any content status, and rely on the content_status field of the returned Entries to show placeholder images while we wait for them to load.

dignifiedquire commented 1 month ago

This should be done once the new willow implementation is integrated