pub async fn record_network_stat(
pool: &SqlitePool,
stat: &NetworkStat,
) -> Result<()>Expand description
Record one relay’s observation, keyed by (key, source) so each relay’s
number is kept separately (non-archival relays legitimately disagree).
An upsert: the table is bounded forever at (metrics × relays) rows — two today — so this can never grow the DB. It must stay an upsert and never become a per-DID insert.
A truncated observation never lowers a stored count. A truncated walk
saw only part of the network, so a smaller number is evidence about the
walk, not about adoption. Without the guard, one slow run that managed a
single 500-repo page would overwrite a complete 2 000 and drag the published
“at least N” down — and because latest_network_stat takes the max across
sources, two relays behind the same operator degrade together, so /about
would sit at the lower figure until a full walk succeeded again. A COMPLETE
observation always wins, even when smaller (repos genuinely can disappear);
a truncated one may only ever raise the floor — and an EQUAL count raises
nothing, so it is rejected too. That is why the guard reads <= and not
<: the strict form let a truncated walk that merely matched the stored
number rewrite the row and flip truncated on, degrading “2 000” to “at
least 2 000” with no change in adoption.