Constellation, Spacedust, Slingshot, UFOs: atproto crates and services for microcosm

add _idx suffix for clarity (thanks maxh!) +fwd->o

"forward links" now align a little on the "other link" terminology used in the client-facing api

(kind of regret "other" as a term but oh well!)

authored by bad-example.com and committed by tangled.org 2a143bba e12537a8

+39 -31
+17 -14
constellation/src/storage/mem_store.rs
··· 257 257 // extract parts form composite cursor 258 258 let cursor = match after { 259 259 Some(a) => { 260 - let (b, f) = a.split_once(',').ok_or(anyhow!("invalid cursor format"))?; 261 - let b = b 260 + let (b, o) = a.split_once(',').ok_or(anyhow!("invalid cursor format"))?; 261 + let backlink_idx = b 262 262 .parse::<u64>() 263 263 .map_err(|e| anyhow!("invalid cursor.0: {e}"))?; 264 - let f = f 264 + let other_link_idx = o 265 265 .parse::<u64>() 266 266 .map_err(|e| anyhow!("invalid cursor.1: {e}"))?; 267 267 Some(ManyToManyCursor { 268 - backlink: b, 269 - forward_link: f, 268 + backlink_idx, 269 + other_link_idx, 270 270 }) 271 271 } 272 272 None => None, ··· 283 283 let mut items: Vec<(usize, usize, ManyToManyItem)> = Vec::new(); 284 284 285 285 // iterate backwards (who linked to the target?) 286 - for (linker_idx, (did, rkey)) in linkers 286 + for (backlink_idx, (did, rkey)) in linkers 287 287 .iter() 288 288 .enumerate() 289 289 .filter_map(|(i, opt)| opt.as_ref().map(|v| (i, v))) 290 - .skip_while(|(linker_idx, _)| cursor.is_some_and(|c| *linker_idx < c.backlink as usize)) 290 + .skip_while(|(backlink_idx, _)| { 291 + cursor.is_some_and(|c| *backlink_idx < c.backlink_idx as usize) 292 + }) 291 293 .filter(|(_, (did, _))| filter_dids.is_empty() || filter_dids.contains(did)) 292 294 { 293 295 let Some(links) = data.links.get(did).and_then(|m| { ··· 299 301 continue; 300 302 }; 301 303 302 - // iterate forward (which of these links point to the __other__ target?) 303 - for (link_idx, (_, fwd_target)) in links 304 + // iterate forward (which of these links point to the "other" target?) 305 + for (other_link_idx, (_, fwd_target)) in links 304 306 .iter() 305 307 .enumerate() 306 308 .filter(|(_, (p, t))| { 307 309 *p == path_to_other && (filter_targets.is_empty() || filter_targets.contains(t)) 308 310 }) 309 - .skip_while(|(link_idx, _)| { 311 + .skip_while(|(other_link_idx, _)| { 310 312 cursor.is_some_and(|c| { 311 - linker_idx == c.backlink as usize && *link_idx <= c.forward_link as usize 313 + backlink_idx == c.backlink_idx as usize 314 + && *other_link_idx <= c.other_link_idx as usize 312 315 }) 313 316 }) 314 317 .take(limit as usize + 1 - items.len()) ··· 321 324 }, 322 325 other_subject: fwd_target.0.clone(), 323 326 }; 324 - items.push((linker_idx, link_idx, item)); 327 + items.push((backlink_idx, other_link_idx, item)); 325 328 } 326 329 327 330 // page full - eject ··· 331 334 } 332 335 333 336 let next = (items.len() > limit as usize).then(|| { 334 - let (l, f, _) = items[limit as usize - 1]; 335 - format!("{l},{f}") 337 + let (b, o, _) = items[limit as usize - 1]; 338 + format!("{b},{o}") 336 339 }); 337 340 338 341 let items = items
+2 -2
constellation/src/storage/mod.rs
··· 41 41 42 42 #[derive(Copy, Clone, Debug)] 43 43 struct ManyToManyCursor { 44 - backlink: u64, 45 - forward_link: u64, 44 + backlink_idx: u64, 45 + other_link_idx: u64, 46 46 } 47 47 48 48 /// A paged collection whose keys are sorted instead of indexed
+20 -15
constellation/src/storage/rocks_store.rs
··· 1156 1156 let cursor = match after { 1157 1157 Some(a) => { 1158 1158 let (b, f) = a.split_once(',').ok_or(anyhow!("invalid cursor format"))?; 1159 - let b = b 1159 + let backlink_idx = b 1160 1160 .parse::<u64>() 1161 1161 .map_err(|e| anyhow!("invalid cursor.0: {e}"))?; 1162 - let f = f 1162 + let other_link_idx = f 1163 1163 .parse::<u64>() 1164 1164 .map_err(|e| anyhow!("invalid cursor.1: {e}"))?; 1165 1165 Some(ManyToManyCursor { 1166 - backlink: b, 1167 - forward_link: f, 1166 + backlink_idx, 1167 + other_link_idx, 1168 1168 }) 1169 1169 } 1170 1170 None => None, ··· 1195 1195 let mut items: Vec<(usize, usize, ManyToManyItem)> = Vec::new(); 1196 1196 1197 1197 // iterate backlinks (who linked to the target?) 1198 - for (linker_idx, (did_id, rkey)) in 1199 - linkers.0.iter().enumerate().skip_while(|(linker_idx, _)| { 1200 - cursor.is_some_and(|c| *linker_idx < c.backlink as usize) 1201 - }) 1198 + for (backlink_idx, (did_id, rkey)) in 1199 + linkers 1200 + .0 1201 + .iter() 1202 + .enumerate() 1203 + .skip_while(|(backlink_idx, _)| { 1204 + cursor.is_some_and(|c| *backlink_idx < c.backlink_idx as usize) 1205 + }) 1202 1206 { 1203 1207 if did_id.is_empty() 1204 1208 || (!filter_did_ids.is_empty() && !filter_did_ids.contains_key(did_id)) ··· 1215 1219 continue; 1216 1220 }; 1217 1221 1218 - // iterate fwd links (which of these links point to the __other__ target?) 1219 - for (link_idx, RecordLinkTarget(_, fwd_target_id)) in links 1222 + // iterate fwd links (which of these links point to the "other" target?) 1223 + for (other_link_idx, RecordLinkTarget(_, fwd_target_id)) in links 1220 1224 .0 1221 1225 .into_iter() 1222 1226 .enumerate() ··· 1225 1229 && (filter_to_target_ids.is_empty() 1226 1230 || filter_to_target_ids.contains(target_id)) 1227 1231 }) 1228 - .skip_while(|(link_idx, _)| { 1232 + .skip_while(|(other_link_idx, _)| { 1229 1233 cursor.is_some_and(|c| { 1230 - linker_idx == c.backlink as usize && *link_idx <= c.forward_link as usize 1234 + backlink_idx == c.backlink_idx as usize 1235 + && *other_link_idx <= c.other_link_idx as usize 1231 1236 }) 1232 1237 }) 1233 1238 .take(limit as usize + 1 - items.len()) ··· 1254 1259 link_record: record_id, 1255 1260 other_subject: fwd_target_key.0 .0, 1256 1261 }; 1257 - items.push((linker_idx, link_idx, item)); 1262 + items.push((backlink_idx, other_link_idx, item)); 1258 1263 } 1259 1264 1260 1265 // page full - eject ··· 1273 1278 // forward_link_idx are skipped. This correctly resumes mid-record when 1274 1279 // a single backlinker has multiple forward links at path_to_other. 1275 1280 let next = (items.len() > limit as usize).then(|| { 1276 - let (l, f, _) = items[limit as usize - 1]; 1277 - format!("{l},{f}") 1281 + let (b, o, _) = items[limit as usize - 1]; 1282 + format!("{b},{o}") 1278 1283 }); 1279 1284 1280 1285 let items = items