Side B is a substantial architectural refactor that removes cached, incrementally-mutated edge/index state (GroupState) in favor of a minimal ScopeVotes struct that derives rankings on demand, eliminating a whole class of rollback/mutation bugs and simplifying storage schema, with corresponding test updates across many files. Side A is a smaller, more superficial change (selector renaming, reusing entity_section markup in vote compare cards, CSS pruning) that improves consistency but has much lower architectural impact, and even introduces a stray formatting artifact in a match arm.
constitution · epochs · watch · epoch 3
c_c6beb77e8e71 (tommy-mor) vs c_ef71be9831cc (tommy-mor)
download prompt · raw event · cmp_e028a3352dc7cd
council reasoning
B redesigns core ranking state: GroupState’s cached indexes/edges/rollback become ScopeVotes (uuid_votes + recent_votes only), with edges and components derived on demand across reducer, ranking, storage, and pair logic—a lasting architectural simplification. A is useful UI cleanup (data-entity-section selectors, vote cards reusing entity_section, CSS trim) but is surface-level compared with B’s domain-model change.
Side B performs a substantial architectural refactor by replacing cached `GroupState` with `ScopeVotes`, deriving ranking edges and connected components on demand from deduplicated votes, and updating ranking, pairing, storage, replay, and tests accordingly. Side A mainly improves HTML reuse and correctness for multiple entity sections by replacing a fixed `#entity-section` target with per-item selectors and reusing `entity_section` in the vote UI, which is useful but much narrower in long-term impact.
sides
A — c_c6beb77e8e71 (tommy-mor)
message
[8dab9b80] nice
diff preview
diff --git a/server/src/fetch/html.rs b/server/src/fetch/html.rs
index 3e0309ff1c2ac1b17923922d2340ba6710e0f9d1..dadf050515f0473943dad97df5d318032c8cb385 100644
--- a/server/src/fetch/html.rs
+++ b/server/src/fetch/html.rs
@@ -10,13 +10,18 @@ use crate::{
ui_action::UI_RPC_FIELD,
};
-fn entity_panel(node: &NodeState) -> Markup {
+/// CSS selector for Idiomorph / SSE updates of one entity block.
+pub fn entity_section_selector(item: &ItemId) -> String {
+ format!(r#"[data-entity-section="{}"]"#, item.as_str())
+}
+
+pub fn entity_panel(node: &NodeState) -> Markup {
if let Some(markup) = crate::render::reddit::entity_markup(node) {
return markup;
}
html! {
@if let Some(data) = &node.data {
- div id="entity-panel" class="entity-card" {
+ div class="entity-card" {
h2 { (data.title) }
@if let Some(author) = &data.author {
p class="muted small" { "by " (author) }
@@ -76,11 +81,11 @@ pub fn fetch_entity_panel(item: &ItemId, has_data: bool, fetching: bool) -> Mark
}
}
-/// Entity card + fetch control (target `#entity-section` for Idiomorph / SSE).
+/// Entity card + fetch control (morph target [`entity_section_selector`]).
pub fn entity_section(item: &ItemId, node: &NodeState, fetching: bool) -> Markup {
let has_data = node.data.is_some();
html! {
- section id="entity-section" class="demo-panel" {
+ section class="entity-section demo-panel" data-entity-section=(item.as_str()) {
(entity_panel(node))
(fetch_entity_panel(item, has_data, fetching))
}
diff --git a/server/src/fetch/mod.rs b/server/src/fetch/mod.rs
index 35f968c21c69ca557bab7951413e3cfbbccfebfd..f5759a34a1afe4069805441cefde6474a6403550 100644
--- a/server/src/fetch/mod.rs
+++ b/server/src/fetch/mod.rs
@@ -77,8 +77,9 @@ pub fn fetch_entity_stream(
let tree = state.tree.read().await;
let empty = NodeState::default();
let node = tree.get(&id).unwrap_or(&empty);
+ let sel = html::entity_section_selector(&id);
JsBuilder::new()
- .morph_selector("#entity-section", html::entity_section(&id, node, true))
+ .morph_selector(&sel, html::entity_section(&id, node, true))
.build()
};
yield Ok(js_event(fetching_js));
@@ -100,12 +101,13 @@ pub fn fetch_entity_stream(
FetchJobResult::Imported(_)
| FetchJobResult::NotFound
| FetchJobResult::SkippedCached
- | FetchJobResult::SkippedDuplicate => {
+ | FetchJobResult::SkippedDuplicate => {
let tree = state.tree.read().await;
let empty = NodeState::default();
let node = tree.get(&id).unwrap_or(&empty);
+ let sel = html::entity_section_selector(&id);
let mut b = JsBuilder::new()
- .morph_selector("#entity-section", html::entity_section(&id, node, false));
+ .morph_selector(&sel, html::entity_section(&id, node, false));
if kind == FetchKind::Children {
b = b.morph_selector("#ranking-panel", ranking_panel(&id, node, &tree));
}
@@ -115,8 +117,9 @@ pub fn fetch_entity_stream(
let tree = state.tree.read().await;
let empty = NodeState::default();
let node = tree.get(&id).unwrap_or(&empty);
+ let sel = html::entity_section_selector(&id);
let js = JsBuilder::new()
- .morph_selector("#entity-section", html::entity_section(&id, node, false))
+ .morph_selector(&sel, html::entity_section(&id, node, false))
.raw(&error_js(&format!("Reddit rate limit — retry in {reset_secs}s.")))
.build();
yield Ok(js_event(js));
@@ -125,8 +128,9 @@ pub fn fetch_entity_stream(
let tree = state.tree.read().await;
let empty = NodeState::default();
let node = tree.get(&id).unwrap_or(&empty);
+ let sel = html::entity_section_selector(&id);
let js = JsBuilder::new()
- .morph_selector("#entity-section", html::entity_section(&id, node, false))
+ .morph_selector(&sel, html::entity_section(&id, node, false))
.raw(&error_js(&format!("Fetch failed: {msg}")))
.build();
yield Ok(js_event(js));
diff --git a/server/src/html/vote.rs b/server/src/html/vote.rs
index 89ed621ad861214e147add2062224fc4137ff8ad..48752f4d78d4762d1badc44e8df008bf5a45bab4 100644
--- a/server/src/html/vote.rs
+++ b/server/src/html/vote.rs
@@ -8,6 +8,7 @@ use maud::{html, Markup};
use serde::Deserialize;
use crate::{
+ fetch::html::entity_section,
form_template::template_json_compact,
html::JsBuilder,
pair::{children_of, resolve_pair, suggest_next_pair_in_pool},
@@ -169,37 +170,13 @@ pub(crate) fn vote_recorded_morph(
}
fn vote_compare_item_card(tree: &GlobalTree, item: &ItemId, side_class: &str) -> Markup {
- let href = item_href(item);
- let title = child_title(tree, item);
+ let node = tree.get(item).cloned().unwrap_or_else(|| NodeState {
+ id: item.clone(),
+ ..Default::default()
+ });
html! {
div class=(format!("vote-compare-side {side_class}")) {
- a class=(format!("vote-compare-item {side_class}")) href=(href) {
- @if let Some(row) = crate::render::reddit::child_row_markup(tree, item, &href) {
- (row)
- } @else {
- strong { (title) }
- }
- }
- @if let Some(node) = tree.get(item) {
- @if crate::render::reddit::is_reddit_post(item) {
- @if let Some(data) = &node.data {
- @if let Some(src) = data.image_url.as_ref().or(data.thumb_url.as_ref()) {
- figure class="vote-compare-figure" {
- img class="vote-compare-image" src=(src) alt="" loading="lazy";
- }
- }
- @if let Some(author) = &data.author {
- p class="muted small" { "by " (author) }
- }
- }
- } @else if let Some(data) = &node.data {
- @if let Some(body) = &data.body_html {
- div class="vote-compare-item-body" {
- (maud::PreEscaped(body))
- }
- }
- }
- }
+ (entity_section(item, &node, false))
}
}
}
@@ -270,9 +247,6 @@ pub async fn vote_page(
(vote_compare_item_card(&tree, &right, "vote-compare-right"))
}
(vote_back_nav(&parent))
- div id="vote-edge-history-region" {
- (edge_history)
- }
form id="vote-compare-form" method="POST" action="/ui" {
input type="hidden" name=(UI_RPC_FIELD) value=(rpc_json);
input type="hidden" name="ratio_left" id="vote-ratio-left" value="50";
@@ -285,6 +259,9 @@ pub async fn vote_page(
}
(vote_compare_actions(&parent, next_pair.as_ref()))
}
+ div id="vote-edge-history-region" {
+ (edge_history)
+ }
}
};
diff --git a/server/src/render/reddit.rs b/server/src/render/reddit.rs
index 4a18de93cf57d8395ded3caa373a708f39b3f43f..c4f98fc760c32ce1b41a91bd41e97908bd198937 100644
--- a/server/src/render/reddit.rs
+++ b/server/src/render/reddit.rs
@@ -11,7 +11,7 @@ pub fn is_reddit_post(id: &ItemId) -> bool {
id.as_str().starts_with("reddit.com/") && id.as_str().contains("/comments/")
}
-/// Post detail card (`#entity-panel`).
+/// Post detail card (inside [`crate::fetch::html::entity_panel`]).
pub fn entity_markup(node: &NodeState) -> Option<Markup> {
if !is_reddit_post(&node.id) {
return None;
@@ -41,7 +41,7 @@ pub fn child_row_markup(tree: &GlobalTree, id: &ItemId, href: &str) -> Option<Ma
fn post_entity_card(data: &EntityData) -> Markup {
let image = data.image_url.as_ref().or(data.thumb_url.as_ref());
html! {
- div id="entity-panel" class="entity-card reddit-post" {
+ div class="entity-card reddit-post" {
h2 { (data.title) }
@if let Some(author) = &data.author {
p class="muted small" { "by " (author) }
diff --git a/server/static/sorter.css b/server/static/sorter.css
index b95718ce463b200a5667d3014dac2119836a0bef..9379c5f41dedbd41fd8951099a118de1da2a62f4 100644
--- a/server/static/sorter.css
+++ b/server/static/sorter.css
@@ -254,38 +254,11 @@ h1 {
}
.vote-compare-side {
- background: var(--panel);
- border: 1px solid var(--border);
- border-radius: 8px;
- padding: 1rem;
min-height: 120px;
}
-.vote-compare-item {
- color: var(--accent);
- text-decoration: none;
- display: block;
-}
-
-.vote-compare-item:hover {
- text-decoration: underline;
-}
-
-.vote-compare-figure {
- margin: 0.75rem 0 0;
-}
-
-.vote-compare-image {
- display: block;
- max-width: 100%;
- height: auto;
- border-radius: 6px;
- border: 1px solid var(--border);
-}
-
-.vote-compare-item-body {
- margin-top: 0.75rem;
- font-size: 0.9rem;
+.vote-compare-side .entity-section {
+ margin: 0;
}
.vote-compare-nav {
B — c_ef71be9831cc (tommy-mor)
message
[af73743d] Replace GroupState with ScopeVotes and derive edges at ranking time. Store only uuid_votes and recent_votes per scope; rank centrality and pair logic rebuild edge weights on demand instead of maintaining cached state. Co-authored-by: Cursor <cursoragent@cursor.com>
diff preview
diff --git a/server/src/events.rs b/server/src/events.rs
index 8a166d49b4f26835fbc2b58cb1f4bdbf002763b8..015208311f6c5c23a0e8aab068d002a69c89c4e1 100644
--- a/server/src/events.rs
+++ b/server/src/events.rs
@@ -43,7 +43,7 @@ pub enum ViewEvent {
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(tag = "type", rename_all = "snake_case")]
pub enum Event {
- /// Pairwise comparison vote (replayed into the parent node's [`crate::reducer::GroupState`] on boot).
+ /// Pairwise comparison vote (replayed into the parent node's [`crate::reducer::ScopeVotes`] on boot).
/// `scope` is the parent [`crate::path_types::ItemId`] string; empty string is the tree root.
VoteRecorded {
ts: i64,
diff --git a/server/src/html/mod.rs b/server/src/html/mod.rs
index 4eff2e19ed4d303ff8e80c1eabd8a15b4990e643..1e2e7a06856d8a62378741aaf5ed94a4ffed337e 100644
--- a/server/src/html/mod.rs
+++ b/server/src/html/mod.rs
@@ -13,7 +13,7 @@ use crate::{
form_template::template_json_compact,
path_types::ItemId,
ranking::{
- connected_components_from_voted_pairs, ranked_items_subset, RankedItem, MAX_ITERS, TOL,
+ ranked_items_subset, scope_components, RankedItem, MAX_ITERS, TOL,
},
reducer::{GlobalTree, NodeState},
state::AppState,
@@ -397,10 +397,9 @@ pub fn ranking_panel_with_highlights(
tree: &GlobalTree,
highlighted: &HashSet<ItemId>,
) -> Markup {
- let group = &node.local_ranking;
- let n = group.idx_to_item.len();
- let (comps, _isolates) =
- connected_components_from_voted_pairs(n, group.voted_pairs.iter().copied());
+ let scope = &node.votes;
+ let (comps, _isolates, _) =
+ scope_components(scope);
// Each connected component of voted items is its own ranking; isolated and
// never-voted children fall into the "unranked" bucket below.
@@ -410,7 +409,7 @@ pub fn ranking_panel_with_highlights(
if comp.len() < 2 {
continue;
}
- let ranked = ranked_items_subset(group, comp, MAX_ITERS, TOL);
+ let ranked = ranked_items_subset(scope, comp, MAX_ITERS, TOL);
for r in &ranked {
ranked_ids.insert(r.item.clone());
}
diff --git a/server/src/html/vote.rs b/server/src/html/vote.rs
index bf82aef3ad9c5f4e9e877c47dab27beb29a80b8f..3aa00c417c89a9cab3417c650b50ed7c73f08e20 100644
--- a/server/src/html/vote.rs
+++ b/server/src/html/vote.rs
@@ -14,7 +14,7 @@ use crate::{
html::{ranking_panel_with_highlights, scope_theme_style, JsBuilder},
pair::{children_of, resolve_pair, suggest_next_pair_in_pool},
path_types::ItemId,
- reducer::{GlobalTree, GroupState, NodeState, VoteData},
+ reducer::{GlobalTree, NodeState, ScopeVotes, VoteData},
state::{parse_item_param, AppState},
ui_action::UI_RPC_FIELD,
};
@@ -68,8 +68,8 @@ fn ratios_for_page(v: &VoteData, page_left: &ItemId, page_right: &ItemId) -> (i3
}
}
-fn edge_votes(group: &GroupState, left: &ItemId, right: &ItemId) -> Vec<VoteData> {
- group
+fn edge_votes(scope: &ScopeVotes, left: &ItemId, right: &ItemId) -> Vec<VoteData> {
+ scope
.recent_votes
.iter()
.filter(|v| {
@@ -113,11 +113,11 @@ fn slider_value_from_ratios(r_left: i32, r_right: i32) -> i32 {
fn vote_edge_history(
tree: &GlobalTree,
- group: &GroupState,
+ scope: &ScopeVotes,
left: &ItemId,
right: &ItemId,
) -> Markup {
- let mut votes = edge_votes(group, left, right);
+ let mut votes = edge_votes(scope, left, right);
votes.sort_by(|a, b| b.ts.cmp(&a.ts));
let legend_left = child_title(tree, left);
let legend_right = child_title(tree, right);
@@ -228,9 +228,9 @@ pub(crate) fn vote_recorded_morph(
) -> JsBuilder {
let pool = children_of(tree, parent);
let empty = NodeState::default();
- let group = tree.get(parent).unwrap_or(&empty).local_ranking.clone();
- let edge_history = vote_edge_history(tree, &group, left, right);
- let next_pair = suggest_next(&group, left, right, &pool);
+ let scope = tree.get(parent).unwrap_or(&empty).votes.clone();
+ let edge_history = vote_edge_history(tree, &scope, left, right);
+ let next_pair = suggest_next(&scope, left, right, &pool);
let actions = vote_compare_actions(parent, next_pair.as_ref());
let sidebar = vote_ranking_sidebar(tree, parent, left, right);
JsBuilder::new()
@@ -252,12 +252,12 @@ fn vote_compare_item_card(tree: &GlobalTree, item: &ItemId, side_class: &str) ->
}
fn suggest_next(
- group: &GroupState,
+ scope: &ScopeVotes,
left: &ItemId,
right: &ItemId,
pool: &[ItemId],
) -> Option<(ItemId, ItemId)> {
- suggest_next_pair_in_pool(group, pool, Some((left, right)))
+ suggest_next_pair_in_pool(scope, pool, Some((left, right)))
}
pub async fn vote_page(
@@ -284,9 +284,9 @@ pub async fn vote_page(
};
let pool = children_of(&tree, &parent);
- let group = &parent_node.local_ranking;
- let next_pair = suggest_next(group, &left, &right, &pool);
- let edge_history = vote_edge_history(&tree, group, &left, &right);
+ let scope = &parent_node.votes;
+ let next_pair = suggest_next(&scope, &left, &right, &pool);
+ let edge_history = vote_edge_history(&tree, &scope, &left, &right);
let rpc_json = template_json_compact(&serde_json::json!({
"action": "record_vote",
@@ -388,8 +388,8 @@ mod polarity_tests {
let mut tree = GlobalTree::new();
tree.apply_vote(&parent, vote, TEST_ACTOR_UUID);
- let group = &tree.get(&parent).unwrap().local_ranking;
- let ranked = ranked_items(group);
+ let scope = &tree.get(&parent).unwrap().votes;
+ let ranked = ranked_items(scope);
assert_eq!(
ranked[0].item, left,
"left item should rank first when ratio favours the left"
diff --git a/server/src/pair.rs b/server/src/pair.rs
index 42a1b1eb2adf16730d34d0fe23c13d5a75d7ba27..9873295c51526726089875bbfd2f97d7faa91872 100644
--- a/server/src/pair.rs
+++ b/server/src/pair.rs
@@ -11,8 +11,8 @@ use std::collections::{HashMap, HashSet};
use crate::{
path_types::ItemId,
- ranking::{connected_components_from_voted_pairs, ranked_items},
- reducer::{GlobalTree, GroupState},
+ ranking::{pair_is_voted, ranked_items, scope_components},
+ reducer::{GlobalTree, ScopeVotes},
};
fn pairs_match(a: &ItemId, b: &ItemId, x: &ItemId, y: &ItemId) -> bool {
@@ -23,26 +23,15 @@ fn pair_excluded(a: &ItemId, b: &ItemId, exclude: Option<(&ItemId, &ItemId)>) ->
exclude.is_some_and(|(x, y)| pairs_match(a, b, x, y))
}
-fn pair_is_voted(group: &GroupState, a: &ItemId, b: &ItemId) -> bool {
- let Some(&ai) = group.item_to_idx.get(a) else {
- return false;
- };
- let Some(&bi) = group.item_to_idx.get(b) else {
- return false;
- };
- let (i, j) = if ai < bi { (ai, bi) } else { (bi, ai) };
- group.voted_pairs.contains(&(i, j))
-}
struct ComponentLayout {
ids: HashMap<ItemId, usize>,
established: HashSet<usize>,
}
-fn component_layout(group: &GroupState, pool: &[ItemId]) -> ComponentLayout {
- let n = group.idx_to_item.len();
- let (comps, isolates) =
- connected_components_from_voted_pairs(n, group.voted_pairs.iter().copied());
+fn component_layout(scope: &ScopeVotes, pool: &[ItemId]) -> ComponentLayout {
+ let (comps, isolates, idx_to_item) = scope_components(scope);
+ let n = idx_to_item.len();
let mut established = HashSet::new();
let mut ids: HashMap<ItemId, usize> = HashMap::new();
@@ -52,14 +41,14 @@ fn component_layout(group: &GroupState, pool: &[ItemId]) -> ComponentLayout {
}
for &idx in comp {
if idx < n {
- ids.insert(group.idx_to_item[idx].clone(), comp_idx);
+ ids.insert(idx_to_item[idx].clone(), comp_idx);
}
}
}
let mut next = comps.len();
for &idx in &isolates {
if idx < n {
- ids.insert(group.idx_to_item[idx].clone(), next);
+ ids.insert(idx_to_item[idx].clone(), next);
next += 1;
}
}
@@ -121,7 +110,7 @@ fn established_groups_in_pool<'a>(
groups
}
-fn ranked_pool_order(group: &GroupState, pool: &[ItemId]) -> Vec<ItemId> {
+fn ranked_pool_order(group: &ScopeVotes, pool: &[ItemId]) -> Vec<ItemId> {
let pool_set: HashSet<_> = pool.iter().collect();
ranked_items(group)
.into_iter()
@@ -132,7 +121,7 @@ fn ranked_pool_order(group: &GroupState, pool: &[ItemId]) -> Vec<ItemId> {
/// Walk 1↔2, 2↔3, …; optional `require_unvoted` skips voted edges.
fn zip_adjacent_pair(
- group: &GroupState,
+ group: &ScopeVotes,
order: &[ItemId],
exclude: Option<(&ItemId, &ItemId)>,
require_unvoted: bool,
@@ -153,7 +142,7 @@ fn zip_adjacent_pair(
/// Grow the voted graph toward one component (no rank centrality).
fn suggest_grow_pair(
- group: &GroupState,
+ group: &ScopeVotes,
pool: &[ItemId],
layout: &ComponentLayout,
exclude: Option<(&ItemId, &ItemId)>,
@@ -216,7 +205,7 @@ fn suggest_grow_pair(
/// Pick the next pair to vote on within `pool`.
pub fn suggest_next_pair_in_pool(
- group: &GroupState,
+ group: &ScopeVotes,
pool: &[ItemId],
exclude: Option<(&ItemId, &ItemId)>,
) -> Option<(ItemId, ItemId)> {
@@ -315,7 +304,7 @@ pub fn resolve_pair(
(None, None) => {
let group = tree
.get(parent)
- .map(|n| &n.local_ranking)
+ .map(|n| &n.votes)
.cloned()
.unwrap_or_default();
suggest_next_pair_in_pool(&group, &children, None).ok_or(PairError::NoPair)
@@ -398,7 +387,7 @@ mod tests {
"https://reddit.com/r/rust/b",
],
);
- let group = tree.get(&parent).unwrap().local_ranking.clone();
+ let group = tree.get(&parent).unwrap().votes.clone();
let pool = children_of(&tree, &parent);
assert!(!pair_is_voted(&group, &pool[0], &pool[1]));
assert!(suggest_next_pair_in_pool(&group, &pool, None).is_some());
@@ -417,7 +406,7 @@ mod tests {
);
let vote = test_vote(1, "https://reddit.com/r/rust/a", "https://reddit.com/r/rust/b", 2, 1);
apply(&mut tree, &parent, vote);
- let group = tree.get(&parent).unwrap().local_ranking.clone();
+ let group = tree.get(&parent).unwrap().votes.clone();
let pool = children_of(&tree, &parent);
let (l, r) = suggest_next_pair_in_pool(&group, &pool, None).unwrap();
let voted_ab = (l.as_str() == "https://reddit.com/r/rust/a" && r.as_str() == "https://reddit.com/r/rust/b")
@@ -441,7 +430,7 @@ mod tests {
let cd = test_vote(2, "https://reddit.com/r/rust/c", "https://reddit.com/r/rust/d", 2, 1);
apply(&mut tree, &parent, ab);
apply(&mut tree, &parent, cd);
- let group = tree.get(&parent).unwrap().local_ranking.clone();
+ let group = tree.get(&parent).unwrap().votes.clone();
let pool = children_of(&tree, &parent);
let pair = suggest_next_pair_in_pool(&group, &pool, None).unwrap();
let chosen = pair_set(&pair);
@@ -467,7 +456,7 @@ mod tests {
);
let ab = test_vote(1, "https://reddit.com/r/rust/a", "https://reddit.com/r/rust/b", 2, 1);
apply(&mut tree, &parent, ab);
- let group = tree.get(&parent).unwrap().local_ranking.clone();
+ let group = tree.get(&parent).unwrap().votes.clone();
let pool = children_of(&tree, &parent);
let pair = suggest_next_pair_in_pool(&group, &pool, None).unwrap();
let chosen = pair_set(&pair);
@@ -496,7 +485,7 @@ mod tests {
);
let ab = test_vote(1, "https://reddit.com/r/rust/a", "https://reddit.com/r/rust/b", 2, 1);
apply(&mut tree, &parent, ab);
- let group = tree.get(&parent).unwrap().local_ranking.clone();
+
… preview truncated; 38,568 characters omittedHardlinks — judgments / attempts / prompt
judgments
attempts
Prompt text is loaded only by the download route.