Changeset dc41bef in Klonkt for src/routes/posts.js


Ignore:
Timestamp:
07/01/2026 06:23:10 PM (2 months ago)
Author:
roboburr <roboburr@…>
Branches:
main
Children:
43273c9
Parents:
7b07035
Message:

feat(fediverse): fetch remote reply threads (cached, stale-while-revalidate)

A local post's "From the fediverse" section only had replies that were delivered
to us; replies-to-replies living on other servers were missed. A background crawl
now pulls the AS2 replies collections of the replies we have and caches any new
ones in ap_interactions. It never runs in a page request — the view renders from
cache and a stale post triggers a background refresh for the next view. Bounded
(depth 3 / 30 fetches), polite (serial), PULL only, respects blocks + SSRF guard.

  • src/services/ActivityPubService.js — crawlThread() (bounded BFS over reply collections), collectReplyItems() (paged AS2 collection reader), and the maybeCrawlThread() stale-while-revalidate entry (per-post TTL + in-flight lock, timestamp in app_settings).
  • src/routes/posts.js — the post view fires maybeCrawlThread(post.id) after rendering interactions (non-blocking, gated on apEnabled).
  • test/thread-crawl.test.js — entry exists, no-seed no-op, TTL gate.

Co-Authored-By: Claude <noreply@…>

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/routes/posts.js

    r7b07035 rdc41bef  
    11221122    const _apBase = (process.env.PUBLIC_BASE_URL || `${req.protocol}://${req.get('host')}`).replace(/\/+$/, '');
    11231123    fediverse = ActivityPubService.getInteractions(post.id, _apBase, site);
     1124    // Stale-while-revalidate: render from cache now; refresh the remote thread in the
     1125    // background (TTL-gated, non-blocking) so undelivered replies-to-replies fill in next view.
     1126    if (res.locals.apEnabled !== false) ActivityPubService.maybeCrawlThread(post.id);
    11241127  } catch { /* non-fatal */ }
    11251128  // Owner/admin of this site may reply back to a fediverse interaction.
Note: See TracChangeset for help on using the changeset viewer.