Repository navigation
ADFA-5094: offline topic-tree bundle — domain + flat reader - #424
Merged
Merged
Conversation
First half of the offline-browse bundle (Option A). The tree ships flat in the APK (kolibri_tree.jsonl, "topics" variant) and is read one level at a time. TopicNode.fromBundle: a folder built from the generator's precomputed aggregates (subtree bytes/count, measured over the whole content DB) instead of summed from children, since the flat bundle carries only one level. Adds looseResourceCount / looseResourceBytes so a mixed level can show "N resources here" without the leaves the bundle folds away; the live source fills those when online. of() is unchanged. BundledTreeIndex: pure in-memory index over the JSONL, built line by line so the file never lands in one list; fetchOneLevel(nodeId) returns the node with its direct child folders, each carrying its own aggregates. Never throws. Tests: TopicNode.fromBundle trust/clamp/bad-id; BundledTreeIndex one-level assembly, drill-down, unknown-node null, and blank/malformed/duplicate skipping. Next: BundledTreeSource (asset/overlay wrapper), wire as last tree fallback, register the R2 refresh, picker loose-aggregate line, bundle the asset.
BundledTreeSource reads the flat tree bundle (kolibri_tree.jsonl) from the APK asset, or a newer copy pulled from Cloudflare, mirroring BundledCatalogSource: parsed once into a BundledTreeIndex, cached for the process, reloaded when the overlay's mtime changes. Implements TreeSource — never throws; a missing asset or an unknown node id is a null return. Wired last in the tree chain: Local (box) -> Studio (online) -> Bundle (offline floor), so the live sources win when they can answer and the bundle lets the user browse a channel with the box unimported and no internet. Registers the tree's weekly + opportunistic R2 refresh alongside the catalog's, keyed separately. Degrades cleanly before the asset exists: no asset -> empty index -> null -> the chain behaves exactly as before (Local -> Studio).
From code review: the tree bundle is ~16 MB against the catalog's ~83 KB, so a weekly metered pull would spend the user's mobile data for a freshness nicety the APK asset already floors. Parameterize the refresh scheduler's network type (existing 4-arg calls keep CONNECTED, so the catalog is unchanged) and register the tree's weekly + opportunistic refresh as UNMETERED.
…/ADFA-5094-offline-tree-bundle
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Adds the domain and reader for browsing the Kolibri topic tree offline: the tree
ships flat in the APK (kolibri_tree.jsonl, "topics" variant) and is read one level
at a time.
TopicNode.fromBundle builds a folder from the generator's precomputed aggregates
(subtree bytes/count, measured over the whole content DB) instead of summing them
from children, since the flat bundle carries only one level. It adds
looseResourceCount / looseResourceBytes so a mixed level can show "N resources here"
without the leaves the bundle folds away; the live source (Studio/box) fills those
when online. of() is unchanged.
BundledTreeIndex is a pure, in-memory index over the JSONL, built line by line so
the file never lands in a single list; fetchOneLevel(nodeId) returns the node with
its direct child folders, each carrying its own aggregates. Never throws — a bad
line is skipped, an unknown node id returns null.
Inert on its own: nothing consumes BundledTreeIndex yet, so behaviour is unchanged.
A follow-up wires it as the last tree fallback (Local → Studio → Bundle), registers
the R2 refresh, and bundles the asset.
Verified: JVM unit tests — TopicNode.fromBundle (trust/clamp/bad-id) and
BundledTreeIndex (one-level assembly, drill-down, unknown-node null,
blank/malformed/duplicate skipping). Sources parse-checked.