From e502b39aca348e03493a706c773f55376be4bc18 Mon Sep 17 00:00:00 2001 From: Niels Mokkenstorm Date: Thu, 16 Jul 2026 22:51:26 +0200 Subject: [PATCH] refactor(server): read variant_source straight off the catalog index adoption_count now reads catalog_index's own maintained tally instead of calling Constellation live per request, matching releases (already a direct catalog_index.list read after the row-module extraction). Kills the browse handler's last per-request network dependency; the unused Constellation backlink helper and its source constant go with it. --- server/src/at_record_server/wiring.gleam | 30 +++++++++--------------- 1 file changed, 11 insertions(+), 19 deletions(-) diff --git a/server/src/at_record_server/wiring.gleam b/server/src/at_record_server/wiring.gleam index d4dab8a..3701d7d 100644 --- a/server/src/at_record_server/wiring.gleam +++ b/server/src/at_record_server/wiring.gleam @@ -17,10 +17,6 @@ import gleam/dynamic/decode import gleam/option.{None} import gleam/result -/// Backlink source for adoption: shelf.entry rows whose `release` field -/// points at the release uri. -const shelf_entry_release_source = "dev.mokkenstorm.crate.shelf.entry:release.uri" - pub fn context( client client: Client, static_directory static_directory: String, @@ -45,25 +41,21 @@ pub fn context( catalog:, known_users:, catalog_index:, - variant_source: variant_source(catalog, catalog_index), + variant_source: variant_source(catalog_index), oauth:, ) } -/// The resolution layer's read port: candidate rows read straight off the -/// maintained `catalog_index` (its rows already carry the chain edges, so no -/// per-row fetch is needed), with adoption still tallied live from -/// Constellation. -fn variant_source( - catalog: catalog_deps.Deps, - catalog_index: catalog_index.Store, -) -> catalog_source.Source { - catalog_source.Source(releases: catalog_index.list, adoption_count: fn(uri) { - case catalog.backlinks(uri, shelf_entry_release_source) { - Ok(page) -> page.total - Error(_) -> 0 - } - }) +/// The resolution layer's read port, built directly over the maintained +/// `catalog_index`: its rows already carry the chain edges, and its own +/// adoption tally is the same public count Constellation would recompute +/// live, just already indexed -- so neither field costs a per-request +/// network round trip. +fn variant_source(catalog_index: catalog_index.Store) -> catalog_source.Source { + catalog_source.Source( + releases: catalog_index.list, + adoption_count: catalog_index.adoption_count, + ) } fn text_sender(client: Client) { -- 2.51.2