Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions crates/y-sweet-core/src/doc_sync.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::{doc_connection::DOC_NAME, store::Store, sync::awareness::Awareness, sync_kv::SyncKv};
use anyhow::{anyhow, Context, Result};
use std::sync::{Arc, RwLock};
use yrs::{updates::decoder::Decode, Doc, ReadTxn, StateVector, Subscription, Transact, Update};
use yrs::{updates::decoder::Decode, ReadTxn, StateVector, Subscription, Transact, Update};
use yrs_kvstore::DocOps;

pub struct DocWithSyncKv {
Expand All @@ -24,6 +24,7 @@ impl DocWithSyncKv {
key: &str,
store: Option<Arc<Box<dyn Store>>>,
dirty_callback: F,
skip_gc: bool,
) -> Result<Self>
where
F: Fn() + Send + Sync + 'static,
Expand All @@ -33,7 +34,10 @@ impl DocWithSyncKv {
.context("Failed to create SyncKv")?;

let sync_kv = Arc::new(sync_kv);
let doc = Doc::new();
let doc = yrs::Doc::with_options(yrs::Options {
skip_gc,
..yrs::Options::default()
});

{
let mut txn = doc.transact_mut();
Expand Down
2 changes: 1 addition & 1 deletion crates/y-sweet-worker/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

23 changes: 14 additions & 9 deletions crates/y-sweet-worker/src/durable_object.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,20 @@ impl YServe {
.try_into()
.expect("Should be able to convert timeout interval to i64");

let doc = DocWithSyncKv::new(doc_id, store, move || {
let storage = storage.clone();
wasm_bindgen_futures::spawn_local(async move {
console_log!("Setting alarm.");
if let Err(e) = storage.0.set_alarm(timeout_interval_ms).await {
console_log!("Error setting alarm: {:?}", e);
}
});
})
let doc = DocWithSyncKv::new(
doc_id,
store,
move || {
let storage = storage.clone();
wasm_bindgen_futures::spawn_local(async move {
console_log!("Setting alarm.");
if let Err(e) = storage.0.set_alarm(timeout_interval_ms).await {
console_log!("Error setting alarm: {:?}", e);
}
});
},
false,
)
.await
.map_err(|e| format!("Error creating doc: {:?}", e))?;

Expand Down
10 changes: 10 additions & 0 deletions crates/y-sweet/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ enum ServSubcommand {

#[clap(long, env = "Y_SWEET_MAX_BODY_SIZE")]
max_body_size: Option<usize>,

#[clap(long, default_value = "false", env = "Y_SWEET_SKIP_GC")]
skip_gc: bool,
},

GenAuth {
Expand Down Expand Up @@ -88,6 +91,9 @@ enum ServSubcommand {

#[clap(long, env = "Y_SWEET_MAX_BODY_SIZE")]
max_body_size: Option<usize>,

#[clap(long, default_value = "false", env = "Y_SWEET_SKIP_GC")]
skip_gc: bool,
},
}

Expand Down Expand Up @@ -175,6 +181,7 @@ async fn main() -> Result<()> {
url_prefix,
prod,
max_body_size,
skip_gc,
} => {
let auth = if let Some(auth) = auth {
Some(Authenticator::new(auth)?)
Expand Down Expand Up @@ -214,6 +221,7 @@ async fn main() -> Result<()> {
token.clone(),
true,
*max_body_size,
*skip_gc,
)
.await?;

Expand Down Expand Up @@ -266,6 +274,7 @@ async fn main() -> Result<()> {
host,
checkpoint_freq_seconds,
max_body_size,
skip_gc,
} => {
let doc_id = env::var("SESSION_BACKEND_KEY").expect("SESSION_BACKEND_KEY must be set");

Expand Down Expand Up @@ -312,6 +321,7 @@ async fn main() -> Result<()> {
cancellation_token.clone(),
false,
*max_body_size,
*skip_gc,
)
.await?;

Expand Down
17 changes: 14 additions & 3 deletions crates/y-sweet/src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,8 @@ pub struct Server {
/// Disabled for single-doc mode, since we only have one doc.
doc_gc: bool,
max_body_size: Option<usize>,
/// Whether to skip garbage collection in Yrs documents.
skip_gc: bool,
}

impl Server {
Expand All @@ -103,6 +105,7 @@ impl Server {
cancellation_token: CancellationToken,
doc_gc: bool,
max_body_size: Option<usize>,
skip_gc: bool,
) -> Result<Self> {
Ok(Self {
docs: Arc::new(DashMap::new()),
Expand All @@ -114,6 +117,7 @@ impl Server {
cancellation_token,
doc_gc,
max_body_size,
skip_gc,
})
}

Expand Down Expand Up @@ -141,9 +145,14 @@ impl Server {
pub async fn load_doc(&self, doc_id: &str) -> Result<()> {
let (send, recv) = channel(1024);

let dwskv = DocWithSyncKv::new(doc_id, self.store.clone(), move || {
send.try_send(()).unwrap();
})
let dwskv = DocWithSyncKv::new(
doc_id,
self.store.clone(),
move || {
send.try_send(()).unwrap();
},
self.skip_gc,
)
.await?;

dwskv
Expand Down Expand Up @@ -836,6 +845,7 @@ mod test {
CancellationToken::new(),
true,
None,
false,
)
.await
.unwrap();
Expand Down Expand Up @@ -875,6 +885,7 @@ mod test {
CancellationToken::new(),
true,
None,
false,
)
.await
.unwrap();
Expand Down
Loading