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

Configure Feed

Select the types of activity you want to include in your feed.

record update and deletes

+153 -2
+7 -2
ufos/src/lib.rs
··· 23 23 24 24 impl CollectionCommits { 25 25 pub fn truncating_insert(&mut self, commit: UFOsCommit, limit: usize) { 26 - self.total_seen += 1; 27 - self.dids_estimate.insert(&commit.did); 26 + if let CommitAction::Put(PutAction { 27 + is_update: false, .. 28 + }) = commit.action 29 + { 30 + self.total_seen += 1; 31 + self.dids_estimate.insert(&commit.did); 32 + } 28 33 self.commits.truncate(limit - 1); 29 34 self.commits.push_front(commit); 30 35 }
+146
ufos/src/storage_fjall.rs
··· 1230 1230 1231 1231 collection 1232 1232 } 1233 + pub fn update( 1234 + &mut self, 1235 + did: &str, 1236 + collection: &str, 1237 + rkey: &str, 1238 + record: &str, 1239 + rev: Option<&str>, 1240 + cid: Option<Cid>, 1241 + cursor: u64, 1242 + ) -> Nsid { 1243 + let did = Did::new(did.to_string()).unwrap(); 1244 + let collection = Nsid::new(collection.to_string()).unwrap(); 1245 + let record = RawValue::from_string(record.to_string()).unwrap(); 1246 + let cid = cid.unwrap_or( 1247 + "bafyreidofvwoqvd2cnzbun6dkzgfucxh57tirf3ohhde7lsvh4fu3jehgy" 1248 + .parse() 1249 + .unwrap(), 1250 + ); 1251 + 1252 + let event = CommitEvent { 1253 + collection, 1254 + rkey: RecordKey::new(rkey.to_string()).unwrap(), 1255 + rev: rev.unwrap_or("asdf").to_string(), 1256 + operation: CommitOp::Update, 1257 + record: Some(record), 1258 + cid: Some(cid), 1259 + }; 1260 + 1261 + let (commit, collection) = 1262 + UFOsCommit::from_commit_info(event, did.clone(), Cursor::from_raw_u64(cursor)) 1263 + .unwrap(); 1264 + 1265 + self.batch 1266 + .commits_by_nsid 1267 + .entry(collection.clone()) 1268 + .or_default() 1269 + .truncating_insert(commit, 1); 1270 + 1271 + collection 1272 + } 1273 + pub fn delete( 1274 + &mut self, 1275 + did: &str, 1276 + collection: &str, 1277 + rkey: &str, 1278 + rev: Option<&str>, 1279 + cursor: u64, 1280 + ) -> Nsid { 1281 + let did = Did::new(did.to_string()).unwrap(); 1282 + let collection = Nsid::new(collection.to_string()).unwrap(); 1283 + let event = CommitEvent { 1284 + collection, 1285 + rkey: RecordKey::new(rkey.to_string()).unwrap(), 1286 + rev: rev.unwrap_or("asdf").to_string(), 1287 + operation: CommitOp::Delete, 1288 + record: None, 1289 + cid: None, 1290 + }; 1291 + 1292 + let (commit, collection) = 1293 + UFOsCommit::from_commit_info(event, did, Cursor::from_raw_u64(cursor)).unwrap(); 1294 + 1295 + self.batch 1296 + .commits_by_nsid 1297 + .entry(collection.clone()) 1298 + .or_default() 1299 + .truncating_insert(commit, 1); 1300 + 1301 + collection 1302 + } 1233 1303 } 1234 1304 1235 1305 #[test] ··· 1275 1345 1276 1346 let records = 1277 1347 read.get_records_by_collections(&vec![&Nsid::new("d.e.f".to_string()).unwrap()], 2)?; 1348 + assert_eq!(records.len(), 0); 1349 + 1350 + Ok(()) 1351 + } 1352 + 1353 + #[test] 1354 + fn test_update_one() -> anyhow::Result<()> { 1355 + let (read, mut write) = fjall_db(); 1356 + 1357 + let mut batch = TestBatch::default(); 1358 + let collection = batch.create( 1359 + "did:plc:inze6wrmsm7pjl7yta3oig77", 1360 + "a.b.c", 1361 + "rkey-asdf", 1362 + "{}", 1363 + Some("rev-a"), 1364 + None, 1365 + 100, 1366 + ); 1367 + write.insert_batch(batch.batch)?; 1368 + 1369 + let mut batch = TestBatch::default(); 1370 + batch.update( 1371 + "did:plc:inze6wrmsm7pjl7yta3oig77", 1372 + "a.b.c", 1373 + "rkey-asdf", 1374 + r#"{"ch": "ch-ch-ch-changes"}"#, 1375 + Some("rev-z"), 1376 + None, 1377 + 101, 1378 + ); 1379 + write.insert_batch(batch.batch)?; 1380 + 1381 + let (records, dids) = read.get_counts_by_collection(&collection)?; 1382 + assert_eq!(records, 1); 1383 + assert_eq!(dids, 1); 1384 + 1385 + let records = read.get_records_by_collections(&vec![&collection], 2)?; 1386 + assert_eq!(records.len(), 1); 1387 + let rec = &records[0]; 1388 + assert_eq!(rec.record.get(), r#"{"ch": "ch-ch-ch-changes"}"#); 1389 + assert_eq!(rec.is_update, true); 1390 + Ok(()) 1391 + } 1392 + 1393 + #[test] 1394 + fn test_delete_one() -> anyhow::Result<()> { 1395 + let (read, mut write) = fjall_db(); 1396 + 1397 + let mut batch = TestBatch::default(); 1398 + let collection = batch.create( 1399 + "did:plc:inze6wrmsm7pjl7yta3oig77", 1400 + "a.b.c", 1401 + "rkey-asdf", 1402 + "{}", 1403 + Some("rev-a"), 1404 + None, 1405 + 100, 1406 + ); 1407 + write.insert_batch(batch.batch)?; 1408 + 1409 + let mut batch = TestBatch::default(); 1410 + batch.delete( 1411 + "did:plc:inze6wrmsm7pjl7yta3oig77", 1412 + "a.b.c", 1413 + "rkey-asdf", 1414 + Some("rev-z"), 1415 + 101, 1416 + ); 1417 + write.insert_batch(batch.batch)?; 1418 + 1419 + let (records, dids) = read.get_counts_by_collection(&collection)?; 1420 + assert_eq!(records, 1); 1421 + assert_eq!(dids, 1); 1422 + 1423 + let records = read.get_records_by_collections(&vec![&collection], 2)?; 1278 1424 assert_eq!(records.len(), 0); 1279 1425 1280 1426 Ok(())