@@ -280,11 +280,14 @@ impl DocDBStorage {
280
280
#[ async_trait]
281
281
impl DocStorage < JwstStorageError > for DocDBStorage {
282
282
async fn detect_workspace ( & self , workspace_id : & str ) -> JwstStorageResult < bool > {
283
+ if self . workspaces . read ( ) . await . contains_key ( workspace_id) {
284
+ return Ok ( true ) ;
285
+ }
286
+
283
287
trace ! ( "check workspace exists: get lock" ) ;
284
288
let _lock = self . bucket . read ( ) . await ;
285
289
286
- Ok ( self . workspaces . read ( ) . await . contains_key ( workspace_id)
287
- || Self :: workspace_count ( & self . pool , workspace_id) . await . map ( |c| c > 0 ) ?)
290
+ Ok ( Self :: workspace_count ( & self . pool , workspace_id) . await . map ( |c| c > 0 ) ?)
288
291
}
289
292
290
293
async fn get_or_create_workspace ( & self , workspace_id : String ) -> JwstStorageResult < Workspace > {
@@ -319,11 +322,11 @@ impl DocStorage<JwstStorageError> for DocDBStorage {
319
322
}
320
323
321
324
async fn delete_workspace ( & self , workspace_id : & str ) -> JwstStorageResult < ( ) > {
322
- debug ! ( "delete workspace: get lock" ) ;
323
- let _lock = self . bucket . write ( ) . await ;
324
-
325
325
debug ! ( "delete workspace cache: {workspace_id}" ) ;
326
326
self . workspaces . write ( ) . await . remove ( workspace_id) ;
327
+
328
+ debug ! ( "delete workspace: get lock" ) ;
329
+ let _lock = self . bucket . write ( ) . await ;
327
330
DocDBStorage :: delete_workspace ( & self . pool , workspace_id) . await ?;
328
331
329
332
Ok ( ( ) )
@@ -361,13 +364,12 @@ impl DocStorage<JwstStorageError> for DocDBStorage {
361
364
}
362
365
363
366
async fn update_doc_with_guid ( & self , workspace_id : String , data : & [ u8 ] ) -> JwstStorageResult < ( ) > {
364
- debug ! ( "write_update: get lock" ) ;
365
- let _lock = self . bucket . write ( ) . await ;
366
-
367
367
trace ! ( "write_update: {:?}" , data) ;
368
368
let mut decoder = RawDecoder :: new ( data. to_vec ( ) ) ;
369
369
let guid = decoder. read_var_string ( ) ?;
370
370
371
+ debug ! ( "write_update: get lock" ) ;
372
+ let _lock = self . bucket . write ( ) . await ;
371
373
self . update ( & self . pool , & workspace_id, & guid, decoder. drain ( ) ) . await ?;
372
374
373
375
Ok ( ( ) )
0 commit comments