perf(server): fix broadcast loops, avoid locking db on index, eliminate O(N*M) search, and fix db loss
This commit is contained in:
1 parent
1e39122e05
commit
27aba454e2
4 files changed
+69
-54
No files matched your search
+11
-9
@@ -28,18 +28,20 @@ impl<T: DeserializeOwned + Default + Serialize + Clone + Send + Sync + 'static>
|
||||
let key_inner = key_clone.clone();
|
||||
let json_data = {
|
||||
let lock = cache_clone.read().unwrap_or_else(|e| e.into_inner());
|
||||
serde_json::to_vec(&*lock).unwrap_or_default()
|
||||
serde_json::to_vec(&*lock).ok()
|
||||
};
|
||||
|
||||
let _ = tokio::task::spawn_blocking(move || {
|
||||
if let Ok(write_txn) = db_inner.begin_write() {
|
||||
if let Ok(mut table) = write_txn.open_table(STORE_TABLE) {
|
||||
let _ = table.insert(key_inner.as_str(), json_data.as_slice());
|
||||
if let Some(json_data) = json_data {
|
||||
let _ = tokio::task::spawn_blocking(move || {
|
||||
if let Ok(write_txn) = db_inner.begin_write() {
|
||||
if let Ok(mut table) = write_txn.open_table(STORE_TABLE) {
|
||||
let _ = table.insert(key_inner.as_str(), json_data.as_slice());
|
||||
}
|
||||
let _ = write_txn.commit();
|
||||
}
|
||||
let _ = write_txn.commit();
|
||||
}
|
||||
})
|
||||
.await;
|
||||
})
|
||||
.await;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
Reference in new issue
Block a user