mirror of
https://github.com/hexedtech/codemp.git
synced 2024-11-22 07:14:50 +01:00
feat: send md5 hash with rawops
this should have a tiny impact on performance, but should be monitored
This commit is contained in:
parent
fb7f4c1b31
commit
1e3439e08e
1 changed files with 16 additions and 28 deletions
|
@ -97,10 +97,10 @@ impl ControllerWorker<TextChange> for BufferControllerWorker {
|
||||||
match res {
|
match res {
|
||||||
Err(e) => return tracing::error!("error receiving op from server: {}", e),
|
Err(e) => return tracing::error!("error receiving op from server: {}", e),
|
||||||
Ok(None) => return tracing::warn!("server closed operation stream"),
|
Ok(None) => return tracing::warn!("server closed operation stream"),
|
||||||
Ok(Some(msg)) => match serde_json::from_str(&msg.opseq) {
|
Ok(Some(msg)) => serverside.push_back(
|
||||||
Err(e) => return tracing::error!("error deserializing op from server: {}", e),
|
serde_json::from_str(&msg.opseq)
|
||||||
Ok(op) => serverside.push_back(op),
|
.expect("could not deserialize server opseq")
|
||||||
}
|
),
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -160,33 +160,21 @@ impl ControllerWorker<TextChange> for BufferControllerWorker {
|
||||||
// client operation waiting for us to be enqueued
|
// client operation waiting for us to be enqueued
|
||||||
if serverside.is_empty() {
|
if serverside.is_empty() {
|
||||||
while let Some(op) = clientside.get(0) {
|
while let Some(op) = clientside.get(0) {
|
||||||
if !send_opseq(&mut tx, self.uid.clone(), self.path.clone(), op.clone()).await { break }
|
let opseq = serde_json::to_string(&op).expect("could not serialize opseq");
|
||||||
|
let req = OperationRequest {
|
||||||
|
path: self.path.clone(),
|
||||||
|
hash: format!("{:x}", md5::compute(&self.buffer)),
|
||||||
|
op: Some(RawOp {
|
||||||
|
opseq, user: self.uid.clone(),
|
||||||
|
}),
|
||||||
|
};
|
||||||
|
if let Err(e) = tx.edit(req).await {
|
||||||
|
tracing::warn!("server rejected operation: {}", e);
|
||||||
|
break;
|
||||||
|
}
|
||||||
clientside.pop_front();
|
clientside.pop_front();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn send_opseq(tx: &mut BufferClient<Channel>, uid: String, path: String, op: OperationSeq) -> bool {
|
|
||||||
let opseq = match serde_json::to_string(&op) {
|
|
||||||
Ok(x) => x,
|
|
||||||
Err(e) => {
|
|
||||||
tracing::warn!("could not serialize opseq: {}", e);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
let req = OperationRequest {
|
|
||||||
path, hash: "".into(),
|
|
||||||
op: Some(RawOp {
|
|
||||||
opseq, user: uid,
|
|
||||||
}),
|
|
||||||
};
|
|
||||||
match tx.edit(req).await {
|
|
||||||
Ok(_) => true,
|
|
||||||
Err(e) => {
|
|
||||||
tracing::error!("error sending edit: {}", e);
|
|
||||||
false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
Loading…
Reference in a new issue