alpha
Login
or
Join now
microcosm.blue
/
microcosm-rs
Star
0
Fork
3
Atom
Configure Feed
Issues
Pull Requests
Commits
Tags
Feed URL
Select the types of activity you want to include in your feed.
Constellation, Spacedust, Slingshot, UFOs: atproto crates and services for microcosm
Star
0
Fork
3
Atom
Configure Feed
Issues
Pull Requests
Commits
Tags
Feed URL
Select the types of activity you want to include in your feed.
Overview
Issues
Pulls
Pipelines
record update and deletes
author
phil
date
1 year ago
(Apr 7, 2025, 4:32 PM -0400)
commit
ddcf6f10
ddcf6f1062135731c2b52d1e8db7061ae5d1c6b4
parent
6deb998f
6deb998fd214dec65427ef7bc1a7bddaf240a491
+153
-2
2 changed files
Expand all
Collapse all
Unified
Split
ufos
src
lib.rs
storage_fjall.rs
+7
-2
ufos/src/lib.rs
Reviewed
···
23
23
24
24
impl CollectionCommits {
25
25
pub fn truncating_insert(&mut self, commit: UFOsCommit, limit: usize) {
26
26
-
self.total_seen += 1;
27
27
-
self.dids_estimate.insert(&commit.did);
26
26
+
if let CommitAction::Put(PutAction {
27
27
+
is_update: false, ..
28
28
+
}) = commit.action
29
29
+
{
30
30
+
self.total_seen += 1;
31
31
+
self.dids_estimate.insert(&commit.did);
32
32
+
}
28
33
self.commits.truncate(limit - 1);
29
34
self.commits.push_front(commit);
30
35
}
+146
ufos/src/storage_fjall.rs
Reviewed
···
1230
1230
1231
1231
collection
1232
1232
}
1233
1233
+
pub fn update(
1234
1234
+
&mut self,
1235
1235
+
did: &str,
1236
1236
+
collection: &str,
1237
1237
+
rkey: &str,
1238
1238
+
record: &str,
1239
1239
+
rev: Option<&str>,
1240
1240
+
cid: Option<Cid>,
1241
1241
+
cursor: u64,
1242
1242
+
) -> Nsid {
1243
1243
+
let did = Did::new(did.to_string()).unwrap();
1244
1244
+
let collection = Nsid::new(collection.to_string()).unwrap();
1245
1245
+
let record = RawValue::from_string(record.to_string()).unwrap();
1246
1246
+
let cid = cid.unwrap_or(
1247
1247
+
"bafyreidofvwoqvd2cnzbun6dkzgfucxh57tirf3ohhde7lsvh4fu3jehgy"
1248
1248
+
.parse()
1249
1249
+
.unwrap(),
1250
1250
+
);
1251
1251
+
1252
1252
+
let event = CommitEvent {
1253
1253
+
collection,
1254
1254
+
rkey: RecordKey::new(rkey.to_string()).unwrap(),
1255
1255
+
rev: rev.unwrap_or("asdf").to_string(),
1256
1256
+
operation: CommitOp::Update,
1257
1257
+
record: Some(record),
1258
1258
+
cid: Some(cid),
1259
1259
+
};
1260
1260
+
1261
1261
+
let (commit, collection) =
1262
1262
+
UFOsCommit::from_commit_info(event, did.clone(), Cursor::from_raw_u64(cursor))
1263
1263
+
.unwrap();
1264
1264
+
1265
1265
+
self.batch
1266
1266
+
.commits_by_nsid
1267
1267
+
.entry(collection.clone())
1268
1268
+
.or_default()
1269
1269
+
.truncating_insert(commit, 1);
1270
1270
+
1271
1271
+
collection
1272
1272
+
}
1273
1273
+
pub fn delete(
1274
1274
+
&mut self,
1275
1275
+
did: &str,
1276
1276
+
collection: &str,
1277
1277
+
rkey: &str,
1278
1278
+
rev: Option<&str>,
1279
1279
+
cursor: u64,
1280
1280
+
) -> Nsid {
1281
1281
+
let did = Did::new(did.to_string()).unwrap();
1282
1282
+
let collection = Nsid::new(collection.to_string()).unwrap();
1283
1283
+
let event = CommitEvent {
1284
1284
+
collection,
1285
1285
+
rkey: RecordKey::new(rkey.to_string()).unwrap(),
1286
1286
+
rev: rev.unwrap_or("asdf").to_string(),
1287
1287
+
operation: CommitOp::Delete,
1288
1288
+
record: None,
1289
1289
+
cid: None,
1290
1290
+
};
1291
1291
+
1292
1292
+
let (commit, collection) =
1293
1293
+
UFOsCommit::from_commit_info(event, did, Cursor::from_raw_u64(cursor)).unwrap();
1294
1294
+
1295
1295
+
self.batch
1296
1296
+
.commits_by_nsid
1297
1297
+
.entry(collection.clone())
1298
1298
+
.or_default()
1299
1299
+
.truncating_insert(commit, 1);
1300
1300
+
1301
1301
+
collection
1302
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
1348
+
assert_eq!(records.len(), 0);
1349
1349
+
1350
1350
+
Ok(())
1351
1351
+
}
1352
1352
+
1353
1353
+
#[test]
1354
1354
+
fn test_update_one() -> anyhow::Result<()> {
1355
1355
+
let (read, mut write) = fjall_db();
1356
1356
+
1357
1357
+
let mut batch = TestBatch::default();
1358
1358
+
let collection = batch.create(
1359
1359
+
"did:plc:inze6wrmsm7pjl7yta3oig77",
1360
1360
+
"a.b.c",
1361
1361
+
"rkey-asdf",
1362
1362
+
"{}",
1363
1363
+
Some("rev-a"),
1364
1364
+
None,
1365
1365
+
100,
1366
1366
+
);
1367
1367
+
write.insert_batch(batch.batch)?;
1368
1368
+
1369
1369
+
let mut batch = TestBatch::default();
1370
1370
+
batch.update(
1371
1371
+
"did:plc:inze6wrmsm7pjl7yta3oig77",
1372
1372
+
"a.b.c",
1373
1373
+
"rkey-asdf",
1374
1374
+
r#"{"ch": "ch-ch-ch-changes"}"#,
1375
1375
+
Some("rev-z"),
1376
1376
+
None,
1377
1377
+
101,
1378
1378
+
);
1379
1379
+
write.insert_batch(batch.batch)?;
1380
1380
+
1381
1381
+
let (records, dids) = read.get_counts_by_collection(&collection)?;
1382
1382
+
assert_eq!(records, 1);
1383
1383
+
assert_eq!(dids, 1);
1384
1384
+
1385
1385
+
let records = read.get_records_by_collections(&vec![&collection], 2)?;
1386
1386
+
assert_eq!(records.len(), 1);
1387
1387
+
let rec = &records[0];
1388
1388
+
assert_eq!(rec.record.get(), r#"{"ch": "ch-ch-ch-changes"}"#);
1389
1389
+
assert_eq!(rec.is_update, true);
1390
1390
+
Ok(())
1391
1391
+
}
1392
1392
+
1393
1393
+
#[test]
1394
1394
+
fn test_delete_one() -> anyhow::Result<()> {
1395
1395
+
let (read, mut write) = fjall_db();
1396
1396
+
1397
1397
+
let mut batch = TestBatch::default();
1398
1398
+
let collection = batch.create(
1399
1399
+
"did:plc:inze6wrmsm7pjl7yta3oig77",
1400
1400
+
"a.b.c",
1401
1401
+
"rkey-asdf",
1402
1402
+
"{}",
1403
1403
+
Some("rev-a"),
1404
1404
+
None,
1405
1405
+
100,
1406
1406
+
);
1407
1407
+
write.insert_batch(batch.batch)?;
1408
1408
+
1409
1409
+
let mut batch = TestBatch::default();
1410
1410
+
batch.delete(
1411
1411
+
"did:plc:inze6wrmsm7pjl7yta3oig77",
1412
1412
+
"a.b.c",
1413
1413
+
"rkey-asdf",
1414
1414
+
Some("rev-z"),
1415
1415
+
101,
1416
1416
+
);
1417
1417
+
write.insert_batch(batch.batch)?;
1418
1418
+
1419
1419
+
let (records, dids) = read.get_counts_by_collection(&collection)?;
1420
1420
+
assert_eq!(records, 1);
1421
1421
+
assert_eq!(dids, 1);
1422
1422
+
1423
1423
+
let records = read.get_records_by_collections(&vec![&collection], 2)?;
1278
1424
assert_eq!(records.len(), 0);
1279
1425
1280
1426
Ok(())