tangled
alpha
login
or
join now
slices.network
/
slices
137
fork
atom
Highly ambitious ATProtocol AppView service and sdks
137
fork
atom
overview
issues
10
pulls
3
pipelines
only log jetsteam deletes for relevant slices
chadtmiller.com
5 months ago
240cc0d1
9de75385
+72
-25
1 changed file
expand all
collapse all
unified
split
api
src
jetstream.rs
+72
-25
api/src/jetstream.rs
···
337
337
did: &str,
338
338
commit: atproto_jetstream::JetstreamEventDelete,
339
339
) -> Result<()> {
340
340
-
// First check if this DID is an actor in any of our slices
340
340
+
let uri = format!("at://{}/{}/{}", did, commit.collection, commit.rkey);
341
341
+
342
342
+
// Get slices that track this collection
343
343
+
let slice_collections = self.slice_collections.read().await;
344
344
+
let slice_domains = self.slice_domains.read().await;
341
345
let actor_cache = self.actor_cache.read().await;
342
342
-
let is_tracked_actor = actor_cache.keys().any(|(cached_did, _)| cached_did == did);
343
343
-
344
344
-
if !is_tracked_actor {
345
345
-
// DID is not an actor in any slice, skip deletion
346
346
+
347
347
+
let mut relevant_slices: Vec<String> = Vec::new();
348
348
+
349
349
+
for (slice_uri, collections) in slice_collections.iter() {
350
350
+
if !collections.contains(&commit.collection) {
351
351
+
continue;
352
352
+
}
353
353
+
354
354
+
// Get the domain for this slice
355
355
+
let domain = match slice_domains.get(slice_uri) {
356
356
+
Some(d) => d,
357
357
+
None => continue,
358
358
+
};
359
359
+
360
360
+
// Check if this is a primary collection (starts with slice domain)
361
361
+
let is_primary_collection = commit.collection.starts_with(domain);
362
362
+
363
363
+
if is_primary_collection {
364
364
+
// Primary collection - always process deletes
365
365
+
relevant_slices.push(slice_uri.clone());
366
366
+
} else {
367
367
+
// External collection - only process if DID is an actor in this slice
368
368
+
let cache_key = (did.to_string(), slice_uri.clone());
369
369
+
if actor_cache.get(&cache_key).copied().unwrap_or(false) {
370
370
+
relevant_slices.push(slice_uri.clone());
371
371
+
}
372
372
+
}
373
373
+
}
374
374
+
375
375
+
if relevant_slices.is_empty() {
376
376
+
// No relevant slices found, skip deletion
346
377
return Ok(());
347
378
}
348
348
-
349
349
-
// DID is an actor in our system, delete the record globally
350
350
-
let uri = format!("at://{}/{}/{}", did, commit.collection, commit.rkey);
351
351
-
379
379
+
380
380
+
// Delete the record and log only for relevant slices
352
381
match self.database.delete_record_by_uri(&uri, None).await {
353
382
Ok(rows_affected) => {
354
383
if rows_affected > 0 {
355
355
-
info!("✓ Deleted record globally: {} ({} rows)", uri, rows_affected);
384
384
+
info!("✓ Deleted record: {} ({} rows) for {} slice(s)", uri, rows_affected, relevant_slices.len());
356
385
let message = format!("Record deleted from {}", commit.collection);
357
357
-
Logger::global().log_jetstream(LogLevel::Info, &message, Some(serde_json::json!({
358
358
-
"operation": "delete",
359
359
-
"collection": commit.collection,
360
360
-
"did": did,
361
361
-
"uri": uri,
362
362
-
"rows_affected": rows_affected
363
363
-
})));
386
386
+
387
387
+
// Log to each relevant slice
388
388
+
for slice_uri in relevant_slices {
389
389
+
Logger::global().log_jetstream_with_slice(
390
390
+
LogLevel::Info,
391
391
+
&message,
392
392
+
Some(serde_json::json!({
393
393
+
"operation": "delete",
394
394
+
"collection": commit.collection,
395
395
+
"did": did,
396
396
+
"uri": uri,
397
397
+
"rows_affected": rows_affected
398
398
+
})),
399
399
+
Some(&slice_uri)
400
400
+
);
401
401
+
}
364
402
}
365
403
}
366
404
Err(e) => {
367
405
let message = "Failed to delete record";
368
406
error!("{}: {}", message, e);
369
369
-
Logger::global().log_jetstream(LogLevel::Error, message, Some(serde_json::json!({
370
370
-
"operation": "delete",
371
371
-
"collection": commit.collection,
372
372
-
"did": did,
373
373
-
"uri": uri,
374
374
-
"error": e.to_string()
375
375
-
})));
407
407
+
408
408
+
// Log error to each relevant slice
409
409
+
for slice_uri in relevant_slices {
410
410
+
Logger::global().log_jetstream_with_slice(
411
411
+
LogLevel::Error,
412
412
+
message,
413
413
+
Some(serde_json::json!({
414
414
+
"operation": "delete",
415
415
+
"collection": commit.collection,
416
416
+
"did": did,
417
417
+
"uri": uri,
418
418
+
"error": e.to_string()
419
419
+
})),
420
420
+
Some(&slice_uri)
421
421
+
);
422
422
+
}
376
423
}
377
424
}
378
378
-
425
425
+
379
426
Ok(())
380
427
}
381
428