objective categorical abstract machine language personal data server

Use readonly db connection for getRepo

futur.blue 51793f23 c7a2bdb3

verified
Changed files
+33 -7
pegasus
+2 -1
pegasus/lib/api/sync/getRepo.ml
··· 3 3 let handler = 4 4 Xrpc.handler (fun ctx -> 5 5 let {did; _} = Xrpc.parse_query ctx.req params_of_yojson in 6 - let%lwt repo = Repository.load did ~ensure_active:true in 6 + let%lwt user_db = User_store.connect_readonly did in 7 + let%lwt repo = Repository.load did ~ensure_active:true ~user_db in 7 8 let%lwt car_stream = Repository.export_car repo in 8 9 Dream.stream 9 10 ~headers:[("Content-Type", "application/vnd.ipld.car")]
+9
pegasus/lib/data_store.ml
··· 346 346 pool := Some db ; 347 347 Lwt.return db ) 348 348 349 + let connect_readonly ?create () = 350 + if create = Some true then 351 + Util.mkfile_p Util.Constants.pegasus_db_filepath ~perm:0o644 ; 352 + let%lwt db = 353 + Util.connect_sqlite ?create ~write:false Util.Constants.pegasus_db_location 354 + in 355 + let%lwt () = Migrations.run_migrations Data_store db in 356 + Lwt.return db 357 + 349 358 let create_actor ~did ~handle ~email ~password ~signing_key conn = 350 359 let password_hash = Bcrypt.hash password |> Bcrypt.string_of_hash in 351 360 let now = Util.now_ms () in
+9 -5
pegasus/lib/repository.ml
··· 413 413 in 414 414 Lwt.return {commit= new_commit; results} 415 415 416 - let load ?create ?(ensure_active = false) did : t Lwt.t = 416 + let load ?create ?(ensure_active = false) ?user_db did : t Lwt.t = 417 417 let%lwt ds_conn = Data_store.connect () in 418 418 let%lwt user_db = 419 - try%lwt User_store.connect ?create did 420 - with _ -> 421 - Errors.invalid_request ~name:"RepoNotFound" 422 - "your princess is in another castle" 419 + match user_db with 420 + | Some db -> 421 + Lwt.return db 422 + | None -> ( 423 + try%lwt User_store.connect ?create did 424 + with _ -> 425 + Errors.invalid_request ~name:"RepoNotFound" 426 + "your princess is in another castle" ) 423 427 in 424 428 let%lwt actor = 425 429 match%lwt Data_store.get_actor_by_identifier did ds_conn with
+13 -1
pegasus/lib/user_store.ml
··· 483 483 Hashtbl.replace pool_cache did t ; 484 484 Lwt.return t ) 485 485 486 + let connect_readonly ?create did = 487 + if create = Some true then 488 + Util.mkfile_p (Util.Constants.user_db_filepath did) ~perm:0o644 ; 489 + let%lwt db = 490 + Util.connect_sqlite ?create ~write:false 491 + (Util.Constants.user_db_location did) 492 + in 493 + let%lwt () = Migrations.run_migrations User_store db in 494 + Lwt.return {did; db} 495 + 486 496 (* mst blocks; implements Writable_blockstore *) 487 497 488 498 let get_bytes t cid : Blob.t option Lwt.t = ··· 528 538 if List.is_empty entries then Lwt.return_ok 0 529 539 else 530 540 Lwt_result.catch (fun () -> 531 - let%lwt () = Util.use_pool t.db (fun conn -> Bulk.put_blocks entries conn) in 541 + let%lwt () = 542 + Util.use_pool t.db (fun conn -> Bulk.put_blocks entries conn) 543 + in 532 544 Lwt.return (List.length entries) ) 533 545 534 546 let delete_block t cid : (bool, exn) Lwt_result.t =