Read: rows, directory and author pages
The part of load.ts that turns listing results into rows, orders a space as a tree, and loads the directory and author pages.

The second half of src/read/load.ts deals with lists of documents: the row every listing shows, the directory tree of a space, and an author's profile page. It shares the caches and generation guard described in Loading pages, caches and embeds.

Rows

itemOf(server, info, accounts = {}, comments?) converts one HMDocumentInfo (a result of Query or QueryBlock) into a DocItem:

Field

Source

id, href

the ref built from info.id.uid and info.path (or info.id.path), and its /d/… route

title

metadata.name, else the last path segment, else the short id

summary

metadata.summary

date, at

updateTime as a UTC date string and as ms

image

metadata.cover, else metadata.icon, else firstImageInContent, through mediaUrl at size M

authors, moreAuthors

the first three distinct author uids as Person, and how many more

comments

the explicit comments argument, else activitySummary.commentCount, else 0

Names for the face pile come from two places, and never from one request per row:

    namesOf: QueryBlock's accountsMetadata, already in the response.

    lookupNames: for Query results, one cached Account request per distinct author among each row's first three.

isPublic drops results whose visibility is 2, PRIVATE or RESOURCE_VISIBILITY_PRIVATE.

Directory

loadDirectory(server, uid) answers the readDirectory source. An empty uid returns an empty page without a request. Otherwise it runs in parallel:

    Query with includes: [{space: uid, path: "", mode: "AllDescendants"}]

    the cached Account lookup for the space's name

The result is a DirPage (uid, server, title, error, items). The first item is always the home document (title is the account name or Home, depth 0); the tree follows with every depth increased by one.

treeOrder(server, uid, results) builds the tree: "siblings by title, children under their parent". A document whose parent path is not in the results is treated as a root. Siblings sort with localeCompare. Each DirItem is {id, href, title, depth, path}.

On failure the page carries error (the thrown message or Couldn't load the directory.) and is not cached. Successful pages are cached in dirCache under {server}|{uid}.

Author pages

loadAuthor(server, uid) makes two sequential calls:

    Account with id=uid. type: "account-not-found" throws This account isn't known to this server.

    Query with mode: "Children" on the account's space, for its top-level public documents.

The AuthorPage has uid, server, name, avatar (size S), shortId, summary, homeHref (/d/{uid}), error and docs: DocItem[]. A failure returns the base page (short id as the name, home link intact) with error set, uncached, so Retry works without an epoch change. Success is cached in authorCache under {server}|{uid}.

loadAuthors(server, uids) dedupes, drops empty uids and loads each.

Dropping the caches

forgetAll(server) calls forget(server) and also clears dirCache and authorCache for that server. It runs when the refresh epoch changes.

Tests

    cards.test.ts: 4 tests. Three distinct authors and the rest counted, comment count precedence, Query block style fields, and names and counts taken from the QueryBlock response.

    markdown.test.ts lists group: 3 tests using the query-block-posts.json and all-descendants.json fixtures (captured API answers) for rows, the tree and dates.

    load.test.ts: late directory responses cannot repopulate the cache; author listing recovers on retry.

Known limits

    AllDescendants is fetched in one request with no paging. The directory test expects at least 21 rows on hyper.media.

    The directory search is a client-side title filter in the screen, not a server query.

Related

Do you like what you are reading? Subscribe to receive updates.

Unsubscribe anytime

Comments