mirror of
https://github.com/PR0M3TH3AN/bitvid.git
synced 2026-11-03 19:35:28 +00:00
views: exact count unions across relays (fixes cross-relay under-count) (#4)
The watch-page/chart "exact" count relied on the NIP-45 COUNT, but
countEventsAcrossRelays returns bestEstimate = the single relay with the MOST
events — it can't union across relays. So when views are distributed across
relays it under-counted (a video's card showed 19 while the chart's uncapped
list union showed ~63).
exactCountForPointer now lists view events across ALL relays (one on-demand
list, not a storm) and folds the UNION into the deduped dedupeBuckets (one entry
per viewer-window). total = the set size, so it is accurate AND monotonic (never
spuriously decreases on partial relay responses). The per-relay COUNT is kept
only as a lower-bound floor when the list truncates (>2000 events), flagged
partial. The popularity modal passes { exact: true }; since the count flows
through shared pointer state, opening a video corrects its count everywhere.
Grid cards (no exact) still use the §17-capped batched backfill (approximate,
storm-safe) until opened — an accepted accuracy/cost tradeoff.
Also note the ⋯ menu "Event Details" button does nothing (new TODO #31).
Tests: testExactCountUnionsAcrossRelays. Grandfathered viewCounter.js size.
Co-Authored-By: Claude Opus 4.8 <[email protected]>
This commit is contained in:
1 parent
1bc2b06395
commit
36f3c6e127
5 files changed
+164
-26
No files matched your search
+11
-7
@@ -319,13 +319,17 @@ export function openPopularityModal({
|
||||
|
||||
// Headline total: subscribe to the same counter the card uses (stable + cached).
|
||||
try {
|
||||
countToken = subscribeToVideoViewCount(pointer, ({ total } = {}) => {
|
||||
if (closed) return;
|
||||
if (Number.isFinite(total)) {
|
||||
counterTotal = Number(total);
|
||||
renderHeadline();
|
||||
}
|
||||
});
|
||||
countToken = subscribeToVideoViewCount(
|
||||
pointer,
|
||||
({ total } = {}) => {
|
||||
if (closed) return;
|
||||
if (Number.isFinite(total)) {
|
||||
counterTotal = Number(total);
|
||||
renderHeadline();
|
||||
}
|
||||
},
|
||||
{ exact: true },
|
||||
);
|
||||
} catch (error) {
|
||||
devLogger.warn("[popularity] Failed to subscribe to view count:", error);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user