Skip to content

ADFA-5094: offline topic-tree bundle — domain + flat reader - #424

Merged
luisguzman-adfa merged 4 commits into
mainfrom
feat/ADFA-5094-offline-tree-bundle
Aug 17, 2026
Merged

luisguzman-adfa merged 4 commits into
mainfrom
feat/ADFA-5094-offline-tree-bundle

Conversation

@luisguzman-adfa

Copy link
Copy Markdown
Collaborator

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.

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.
@luisguzman-adfa
luisguzman-adfa merged commit 380952c into main Aug 17, 2026
3 checks passed
@luisguzman-adfa
luisguzman-adfa deleted the feat/ADFA-5094-offline-tree-bundle branch August 17, 2026 23:39
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.

1 participant