Skip to content

Commit 28091c3

Browse files
committed
Remove reconciled Gmail drafts by local ID
1 parent e944b85 commit 28091c3

12 files changed

Lines changed: 376 additions & 149 deletions

File tree

crates/locality-core/src/journal.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ pub struct JournalMetadata {
2121
pub previous_push_id: Option<PushId>,
2222
#[serde(default, skip_serializing_if = "Option::is_none")]
2323
pub created_at_unix_ms: Option<u128>,
24+
#[serde(default, skip_serializing_if = "Vec::is_empty")]
25+
pub local_projection_items: Vec<JournalLocalProjectionItem>,
2426
}
2527

2628
impl Default for JournalMetadata {
@@ -32,6 +34,7 @@ impl Default for JournalMetadata {
3234
},
3335
previous_push_id: None,
3436
created_at_unix_ms: None,
37+
local_projection_items: Vec::new(),
3538
}
3639
}
3740
}
@@ -44,6 +47,17 @@ impl JournalMetadata {
4447
..Self::default()
4548
}
4649
}
50+
51+
pub fn with_local_projection_items(mut self, items: Vec<JournalLocalProjectionItem>) -> Self {
52+
self.local_projection_items = items;
53+
self
54+
}
55+
}
56+
57+
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
58+
pub struct JournalLocalProjectionItem {
59+
pub operation_index: usize,
60+
pub local_id: String,
4761
}
4862

4963
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]

crates/localityd/src/push.rs

Lines changed: 43 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ use locality_core::conflict::unresolved_conflict_marker_line;
1919
use locality_core::diff::property_value_from_frontmatter;
2020
use locality_core::freshness::RemoteVersion;
2121
use locality_core::journal::{
22-
JournalApplyEffect, JournalEntry, JournalMetadata, JournalPreimage, JournalStatus,
23-
JournalStore, PushId,
22+
JournalApplyEffect, JournalEntry, JournalLocalProjectionItem, JournalMetadata, JournalPreimage,
23+
JournalStatus, JournalStore, PushId,
2424
};
2525
use locality_core::model::{CanonicalDocument, EntityKind, HydrationState, MountId, RemoteId};
2626
use locality_core::path_projection::{
@@ -341,16 +341,18 @@ where
341341
.ok()
342342
.map(|duration| duration.as_millis());
343343
let readable_diff = prepared.readable_diff.clone();
344+
let local_projection_items =
345+
local_projection_items_for_plan(store, &prepared.mount, prepared.pipeline.plan.as_ref())?;
344346
let mut execution_request = PushExecutionRequest::new(
345347
push_id.clone(),
346348
prepared.mount.mount_id.clone(),
347349
prepared.pipeline.clone(),
348350
)
349351
.with_remote_preconditions(remote_preconditions)
350-
.with_metadata(JournalMetadata::anonymous(
351-
previous_push_id,
352-
created_at_unix_ms,
353-
))
352+
.with_metadata(
353+
JournalMetadata::anonymous(previous_push_id, created_at_unix_ms)
354+
.with_local_projection_items(local_projection_items),
355+
)
354356
.with_readable_diff(readable_diff.clone());
355357

356358
if !prepared.shadows.is_empty() {
@@ -411,6 +413,41 @@ where
411413
}
412414
}
413415

416+
fn local_projection_items_for_plan<S>(
417+
store: &S,
418+
mount: &MountConfig,
419+
plan: Option<&PushPlan>,
420+
) -> LocalityResult<Vec<JournalLocalProjectionItem>>
421+
where
422+
S: VirtualMutationRepository,
423+
{
424+
if !mount.projection.uses_virtual_filesystem() {
425+
return Ok(Vec::new());
426+
}
427+
let Some(plan) = plan else {
428+
return Ok(Vec::new());
429+
};
430+
431+
let mut items = Vec::new();
432+
for (operation_index, operation) in plan.operations.iter().enumerate() {
433+
let source_path = match operation {
434+
PushOperation::CreateEntity { source_path, .. }
435+
| PushOperation::CreateDatabase { source_path, .. } => source_path,
436+
_ => continue,
437+
};
438+
if let Some(mutation) = store
439+
.find_virtual_mutation_by_path(&mount.mount_id, source_path)
440+
.map_err(LocalityError::from)?
441+
{
442+
items.push(JournalLocalProjectionItem {
443+
operation_index,
444+
local_id: mutation.local_id,
445+
});
446+
}
447+
}
448+
Ok(items)
449+
}
450+
414451
fn block_ambiguous_gmail_send_replay<S>(
415452
store: &S,
416453
prepared: &PreparedPush,

0 commit comments

Comments
 (0)