Answers in protobuf from generated structs, and the page reads them (#470)
ipx-wire converted every protobuf answer at run time through prost-reflect and serde_json::Value, so protobuf cost more than the JSON it replaced: decoding 1,488 feeds took 1.50 ms that way against 0.37 ms for serde_json and 0.09 ms for prost's own structs, and GET /api/feeds as protobuf answered about 4 ms after JSON. build.rs now generates those structs (prost-build from protox's descriptors, still no protoc). An answer's JSON goes straight into its struct with serde and out with prost, byte for byte what the runtime path wrote (a test says so); bodies holding a google.protobuf.Value keep the runtime path, as they are only ever read. ipx's calls to the directory and ipx-play build and read the structs directly, through From conversions beside the directory's own types. The page asks for protobuf too, to see what it does in practice. It reads it with web/src/wire.ts, about seventy lines and no library: protobufjs alone was larger gzipped than all protobuf saves the page. build.mts reads the .proto files into a table for it, and the answer names its message in its Content-Type, so the page keeps no table of routes. An answer of null stays JSON, since the empty message would be a feed row of defaults. The offline worker decodes a kept answer to mark what was read offline, and hands the page JSON. The decoder's test caught `pos += varint()[0]`, which adds the length to pos as it was before the varint was read. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -12,7 +12,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
||||
|
||||
### Added
|
||||
|
||||
- `/v1` answers in protobuf for a client that asks for it (`Accept: application/x-protobuf`) and takes a snapshot sent so; JSON stays the default. The messages are in `crates/wire/proto/directory.proto` (#465).
|
||||
- `/v1` answers in protobuf for a client that asks for it (`Accept: application/x-protobuf`) and takes a snapshot sent so; JSON stays the default. The messages are in `crates/wire/proto/directory.proto`, and answers go through structs generated from them (#465, #470).
|
||||
- A `robots.txt` and a sitemap listing the home page, A to Z, every category and every feed, so search engines find the pages, not only the links between them (#380).
|
||||
- `/metrics` counts its requests and their times by route and status, the feeds it checks and those that failed, and the snapshots it takes (#370).
|
||||
- Its log lines inside a trace carry the trace's and span's ids, as ipx's do, so a failed feed check leads to its trace (#375).
|
||||
|
||||
@@ -97,3 +97,98 @@ pub struct Blocked {
|
||||
/// The most a snapshot may list: far more than one server's subscriptions, few enough that one
|
||||
/// request cannot hold the database for long.
|
||||
pub const MAX_SNAPSHOT: usize = 20_000;
|
||||
|
||||
// The same in protobuf (#470): ipx reads and writes these through ipx-wire's structs, which
|
||||
// mirror the ones above field for field.
|
||||
use ipx_wire::pb::directory as pb;
|
||||
|
||||
impl From<pb::Listing> for Listing {
|
||||
fn from(l: pb::Listing) -> Self {
|
||||
Listing {
|
||||
id: l.id,
|
||||
url: l.url,
|
||||
title: l.title,
|
||||
image: l.image,
|
||||
category: l.category,
|
||||
subcategory: l.subcategory,
|
||||
podcast: l.podcast,
|
||||
subscribers: l.subscribers,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<pb::Item> for Item {
|
||||
fn from(i: pb::Item) -> Self {
|
||||
Item {
|
||||
guid: i.guid,
|
||||
title: i.title,
|
||||
link: i.link,
|
||||
published: i.published,
|
||||
duration: i.duration,
|
||||
description: i.description,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<pb::FeedPage> for FeedPage {
|
||||
fn from(p: pb::FeedPage) -> Self {
|
||||
FeedPage {
|
||||
listing: Listing {
|
||||
id: p.id,
|
||||
url: p.url,
|
||||
title: p.title,
|
||||
image: p.image,
|
||||
category: p.category,
|
||||
subcategory: p.subcategory,
|
||||
podcast: p.podcast,
|
||||
subscribers: p.subscribers,
|
||||
},
|
||||
description: p.description,
|
||||
failing: p.failing,
|
||||
items: p.items.into_iter().map(Item::from).collect(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl TryFrom<pb::Me> for Me {
|
||||
type Error = String;
|
||||
fn try_from(m: pb::Me) -> Result<Self, String> {
|
||||
let access = match m.access.as_str() {
|
||||
"ro" => Access::Ro,
|
||||
"rw" => Access::Rw,
|
||||
"rwa" => Access::Rwa,
|
||||
other => return Err(format!("an access level not known here: {other:?}")),
|
||||
};
|
||||
Ok(Me { name: m.name, access })
|
||||
}
|
||||
}
|
||||
|
||||
impl From<pb::Instance> for Instance {
|
||||
fn from(i: pb::Instance) -> Self {
|
||||
Instance { name: i.name, feeds: i.feeds, subscribers: i.subscribers }
|
||||
}
|
||||
}
|
||||
|
||||
impl From<pb::Blocked> for Blocked {
|
||||
fn from(b: pb::Blocked) -> Self {
|
||||
Blocked { id: b.id, url: b.url, title: b.title, at: b.at }
|
||||
}
|
||||
}
|
||||
|
||||
impl From<pb::SnapshotResult> for SnapshotResult {
|
||||
fn from(r: pb::SnapshotResult) -> Self {
|
||||
let n = |v: u64| usize::try_from(v).unwrap_or(usize::MAX);
|
||||
SnapshotResult {
|
||||
accepted: n(r.accepted),
|
||||
refused_private: n(r.refused_private),
|
||||
refused_blocked: n(r.refused_blocked),
|
||||
refused_invalid: n(r.refused_invalid),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<&SnapshotEntry> for pb::SnapshotEntry {
|
||||
fn from(e: &SnapshotEntry) -> Self {
|
||||
pb::SnapshotEntry { url: e.url.clone(), subscribers: e.subscribers, category: e.category.clone() }
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user