···33let handler =
44 Xrpc.handler (fun ctx ->
55 let {did; _} = Xrpc.parse_query ctx.req params_of_yojson in
66- let%lwt repo = Repository.load did ~ensure_active:true in
66+ let%lwt user_db = User_store.connect_readonly did in
77+ let%lwt repo = Repository.load did ~ensure_active:true ~user_db in
78 let%lwt car_stream = Repository.export_car repo in
89 Dream.stream
910 ~headers:[("Content-Type", "application/vnd.ipld.car")]
+9
pegasus/lib/data_store.ml
···346346 pool := Some db ;
347347 Lwt.return db )
348348349349+let connect_readonly ?create () =
350350+ if create = Some true then
351351+ Util.mkfile_p Util.Constants.pegasus_db_filepath ~perm:0o644 ;
352352+ let%lwt db =
353353+ Util.connect_sqlite ?create ~write:false Util.Constants.pegasus_db_location
354354+ in
355355+ let%lwt () = Migrations.run_migrations Data_store db in
356356+ Lwt.return db
357357+349358let create_actor ~did ~handle ~email ~password ~signing_key conn =
350359 let password_hash = Bcrypt.hash password |> Bcrypt.string_of_hash in
351360 let now = Util.now_ms () in
+9-5
pegasus/lib/repository.ml
···413413 in
414414 Lwt.return {commit= new_commit; results}
415415416416-let load ?create ?(ensure_active = false) did : t Lwt.t =
416416+let load ?create ?(ensure_active = false) ?user_db did : t Lwt.t =
417417 let%lwt ds_conn = Data_store.connect () in
418418 let%lwt user_db =
419419- try%lwt User_store.connect ?create did
420420- with _ ->
421421- Errors.invalid_request ~name:"RepoNotFound"
422422- "your princess is in another castle"
419419+ match user_db with
420420+ | Some db ->
421421+ Lwt.return db
422422+ | None -> (
423423+ try%lwt User_store.connect ?create did
424424+ with _ ->
425425+ Errors.invalid_request ~name:"RepoNotFound"
426426+ "your princess is in another castle" )
423427 in
424428 let%lwt actor =
425429 match%lwt Data_store.get_actor_by_identifier did ds_conn with
+13-1
pegasus/lib/user_store.ml
···483483 Hashtbl.replace pool_cache did t ;
484484 Lwt.return t )
485485486486+let connect_readonly ?create did =
487487+ if create = Some true then
488488+ Util.mkfile_p (Util.Constants.user_db_filepath did) ~perm:0o644 ;
489489+ let%lwt db =
490490+ Util.connect_sqlite ?create ~write:false
491491+ (Util.Constants.user_db_location did)
492492+ in
493493+ let%lwt () = Migrations.run_migrations User_store db in
494494+ Lwt.return {did; db}
495495+486496(* mst blocks; implements Writable_blockstore *)
487497488498let get_bytes t cid : Blob.t option Lwt.t =
···528538 if List.is_empty entries then Lwt.return_ok 0
529539 else
530540 Lwt_result.catch (fun () ->
531531- let%lwt () = Util.use_pool t.db (fun conn -> Bulk.put_blocks entries conn) in
541541+ let%lwt () =
542542+ Util.use_pool t.db (fun conn -> Bulk.put_blocks entries conn)
543543+ in
532544 Lwt.return (List.length entries) )
533545534546let delete_block t cid : (bool, exn) Lwt_result.t =