-
-
Notifications
You must be signed in to change notification settings - Fork 104
Finalize backfill package documentation #816
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
Open
sij411
wants to merge
2
commits into
fedify-dev:feat/backfill
Choose a base branch
from
sij411:feat/backfill-wrap-up
base: feat/backfill
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,203 @@ | ||
| --- | ||
| description: >- | ||
| Reconstruct ActivityPub conversations from FEP-f228 context collections or | ||
| reply relationships using the @fedify/backfill package. | ||
| --- | ||
|
|
||
| Conversation backfill | ||
| ===================== | ||
|
|
||
| *This API is available since Fedify 2.3.0.* | ||
|
|
||
| Fedify provides the *@fedify/backfill* package for reconstructing ActivityPub | ||
| conversations that may be incomplete on the local server. It can retrieve | ||
| post-like objects from [FEP-f228] context collections and optionally crawl | ||
| `inReplyTo` ancestors and `replies` descendants. | ||
|
|
||
| [FEP-f228]: https://w3id.org/fep/f228 | ||
|
|
||
|
|
||
| Installation | ||
| ------------ | ||
|
|
||
| ::: code-group | ||
|
|
||
| ~~~~ sh [Deno] | ||
| deno add jsr:@fedify/backfill | ||
| ~~~~ | ||
|
|
||
| ~~~~ sh [npm] | ||
| npm add @fedify/backfill | ||
| ~~~~ | ||
|
|
||
| ~~~~ sh [pnpm] | ||
| pnpm add @fedify/backfill | ||
| ~~~~ | ||
|
|
||
| ~~~~ sh [Yarn] | ||
| yarn add @fedify/backfill | ||
| ~~~~ | ||
|
|
||
| ~~~~ sh [Bun] | ||
| bun add @fedify/backfill | ||
| ~~~~ | ||
|
|
||
| ::: | ||
|
|
||
|
|
||
| Backfilling a conversation | ||
| -------------------------- | ||
|
|
||
| The `backfill()` function accepts a backfill context, a seed object, and | ||
| traversal options. The context supplies a `documentLoader` for dereferencing | ||
| context collections, collection items, reply targets, and replies collections: | ||
|
|
||
| ~~~~ typescript twoslash | ||
| import { backfill, type BackfillDocumentLoader } from "@fedify/backfill"; | ||
| import { lookupObject, Note } from "@fedify/vocab"; | ||
|
|
||
| declare const note: Note; | ||
| // ---cut-before--- | ||
| const documentLoader: BackfillDocumentLoader = (iri, options) => | ||
| lookupObject(iri, { signal: options?.signal }); | ||
|
|
||
| for await ( | ||
| const item of backfill({ documentLoader }, note, { | ||
| maxItems: 20, | ||
| maxRequests: 50, | ||
| }) | ||
| ) { | ||
| console.log(item.id?.href); | ||
| } | ||
| ~~~~ | ||
|
|
||
| The seed object itself is not yielded. If the same object appears in a | ||
| discovered collection, it is skipped by ID. | ||
|
|
||
| By default, `backfill()` uses the `"context-auto"` strategy. It expects the | ||
| seed's `context` to dereference to a `Collection`, `OrderedCollection`, | ||
| `CollectionPage`, or `OrderedCollectionPage`. Ordinary post-like items are | ||
| yielded directly, while supported `Create` activities are unwrapped and their | ||
| objects are yielded. | ||
|
|
||
| If the seed has no context, or its context resolves to a non-collection, | ||
| context strategies yield nothing. | ||
|
|
||
|
|
||
| Strategies | ||
| ---------- | ||
|
|
||
| Strategies run in the configured order. They share request and item budgets, | ||
| abort state, document caching, and object ID deduplication. If multiple | ||
| strategies discover the same object, the first one keeps its `BackfillItem` | ||
| metadata. | ||
|
|
||
| `"context-auto"` | ||
| : Handles both direct post-like objects and supported `Create` activities | ||
| from a context collection. This is the default strategy. | ||
|
|
||
| `"context-objects"` | ||
| : Accepts only post-like objects contained directly in a context collection: | ||
|
|
||
| ~~~~ typescript twoslash | ||
| import { backfill, type BackfillContext } from "@fedify/backfill"; | ||
| import { Note } from "@fedify/vocab"; | ||
|
|
||
| declare const context: BackfillContext; | ||
| declare const note: Note; | ||
| // ---cut-before--- | ||
| for await ( | ||
| const item of backfill(context, note, { | ||
| strategies: ["context-objects"], | ||
| }) | ||
| ) { | ||
| console.log(item.object); | ||
| } | ||
| ~~~~ | ||
|
|
||
| `"context-activities"` | ||
| : Accepts supported activities from a context collection. It currently | ||
| supports `Create` and yields the activity's object rather than the activity | ||
| itself: | ||
|
|
||
| ~~~~ typescript twoslash | ||
| import { backfill, type BackfillContext } from "@fedify/backfill"; | ||
| import { Note } from "@fedify/vocab"; | ||
|
|
||
| declare const context: BackfillContext; | ||
| declare const note: Note; | ||
| // ---cut-before--- | ||
| for await ( | ||
| const item of backfill(context, note, { | ||
| strategies: ["context-activities"], | ||
| }) | ||
| ) { | ||
| console.log(item.object); | ||
| } | ||
| ~~~~ | ||
|
|
||
| `"reply-tree"` | ||
| : Walks `inReplyTo` ancestors and `replies` descendants. It yields | ||
| post-like objects only and does not unwrap Activity objects. This strategy | ||
| is opt-in because it can require substantially more network requests than | ||
| a context collection. | ||
|
|
||
| For hybrid coverage, run the FEP-f228 path first and use reply-tree traversal | ||
| after it: | ||
|
|
||
| ~~~~ typescript twoslash | ||
| import { backfill, type BackfillContext } from "@fedify/backfill"; | ||
| import { Note } from "@fedify/vocab"; | ||
|
|
||
| declare const context: BackfillContext; | ||
| declare const note: Note; | ||
| // ---cut-before--- | ||
| for await ( | ||
| const item of backfill(context, note, { | ||
| strategies: ["context-auto", "reply-tree"], | ||
| maxDepth: 4, | ||
| }) | ||
| ) { | ||
| console.log(item.origin, item.depth, item.object); | ||
| } | ||
| ~~~~ | ||
|
|
||
|
|
||
| Traversal controls | ||
| ------------------ | ||
|
|
||
| `maxItems` | ||
| : Limits the number of yielded objects. Skipped duplicates do not count. | ||
|
|
||
| `maxRequests` | ||
| : Limits calls to `documentLoader`. Embedded objects and collections do not | ||
| count as requests. | ||
|
|
||
| `maxDepth` | ||
| : Limits reply-tree traversal and defaults to 10. Immediate parents and | ||
| direct replies have depth 1; their next-level parents or replies have depth | ||
| 2, and so on. Context collection items have depth 0 and are not limited by | ||
| this option. | ||
|
|
||
| `interval` | ||
| : Adds a delay between `documentLoader` requests. A callback receives the | ||
| zero-based request index. String durations require the global `Temporal` | ||
| API or a polyfill; `Temporal.DurationLike` objects work without the global | ||
| API. | ||
|
|
||
| `signal` | ||
| : Cancels traversal before requests and yields. The signal is also passed to | ||
| `documentLoader`. | ||
|
|
||
|
|
||
| Caching and failures | ||
| -------------------- | ||
|
|
||
| Dereferenced documents are cached in memory for one `backfill()` traversal. | ||
| Applications that need persistent or shared caching can implement it in the | ||
| provided `documentLoader`. | ||
|
|
||
| Failed external dereferences are skipped so other conversation items can still | ||
| be discovered. Failed loads are not retained in the traversal cache, allowing | ||
| the same IRI to be retried if another traversal path reaches it. Aborting the | ||
| provided signal stops traversal instead of skipping the request. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add a link to this pull request as well!