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