@@ -147,57 +147,17 @@ type t =
147147 { key : Kleidos .key
148148 ; did : string
149149 ; db : User_store .t
150- ; mutable block_map : Cid .t String_map .t option
151150 ; mutable commit : (Cid .t * signed_commit ) option }
152151
153- let get_map t : Cid.t String_map.t Lwt.t =
154- let % lwt root, commit =
155- match % lwt User_store. get_commit t.db with
156- | Some (r , c ) ->
157- Lwt. return (r, c)
158- | None ->
159- failwith (" failed to retrieve commit for " ^ t.did)
160- in
161- t.commit < - Some (root, commit) ;
162- match t.block_map with
163- | Some map ->
164- Lwt. return map
165- | _ ->
166- let % lwt map = Mst. build_map {blockstore= t.db; root= commit.data} in
167- t.block_map < - Some map ;
168- Lwt. return map
169-
170152let get_record_cid t path : Cid.t option Lwt.t =
171- let % lwt map = get_map t in
172- Lwt. return @@ String_map. find_opt path map
153+ User_store. get_record_cid t.db path
173154
174155let get_record t path : record option Lwt.t = User_store. get_record t.db path
175156
176- let list_collections t : string list Lwt.t =
177- let module Set = Set. Make (String ) in
178- let % lwt map = get_map t in
179- String_map. bindings map
180- |> List. fold_left
181- (fun (acc : Set.t ) (path , _ ) ->
182- let collection = String. split_on_char '/' path |> List. hd in
183- Set. add collection acc )
184- Set. empty
185- |> Set. to_list |> Lwt. return
157+ let list_collections t : string list Lwt.t = User_store. list_collections t.db
186158
187- let list_all_records t collection : (string * Cid.t * record) list Lwt.t =
188- let % lwt map = get_map t in
189- String_map. bindings map
190- |> List. filter (fun (path , _ ) ->
191- String. starts_with ~prefix: (path ^ " /" ) collection )
192- |> Lwt_list. fold_left_s
193- (fun acc (path , cid ) ->
194- match % lwt User_store. get_record t.db path with
195- | Some record ->
196- Lwt. return
197- ((Format. sprintf " at://%s/%s" t.did path, cid, record) :: acc)
198- | None ->
199- Lwt. return acc )
200- []
159+ let list_records t ?limit ?cursor ?reverse collection =
160+ User_store. list_records t.db ?limit ?cursor ?reverse collection
201161
202162let sign_commit t commit : signed_commit =
203163 let msg = commit |> commit_to_yojson |> Dag_cbor. encode_yojson in
@@ -232,8 +192,6 @@ let put_commit t ?(previous : signed_commit option = None) mst_root :
232192 User_store. put_commit t.db signed |> Lwt_result. get_exn
233193 in
234194 t.commit < - Some (commit_cid, signed) ;
235- (* clear cached blocks so next get_map call rebuilds from the new commit *)
236- t.block_map < - None ;
237195 Lwt. return (commit_cid, signed)
238196
239197let put_initial_commit t : (Cid.t * signed_commit) Lwt.t =
@@ -261,7 +219,6 @@ let apply_writes (t : t) (writes : repo_write list) (swap_commit : Cid.t option)
261219 let mst : Cached_mst.t ref =
262220 ref (Cached_mst. create cached_store prev_commit.data)
263221 in
264- t.block_map < - None ;
265222 (* ops to emit, built in loop because prev_data (previous cid) is otherwise inaccessible *)
266223 let commit_ops : commit_evt_op list ref = ref [] in
267224 let added_leaves = ref Block_map. empty in
@@ -477,7 +434,7 @@ let load ?create ?(ensure_active = false) did : t Lwt.t =
477434 in
478435 let key = Kleidos. parse_multikey_str signing_key in
479436 let % lwt commit = User_store. get_commit user_db in
480- Lwt. return {key; did; db= user_db; block_map = None ; commit}
437+ Lwt. return {key; did; db= user_db; commit}
481438
482439let export_car t : Car.stream Lwt.t =
483440 let % lwt root, commit =
@@ -629,8 +586,6 @@ let import_car t (stream : Car.stream) : (t, exn) Lwt_result.t =
629586 let $! () = User_store.Bulk. put_blob_refs blob_refs conn in
630587 Lwt. return_ok () ) )
631588 in
632- (* clear cached block_map so it's rebuilt on next access *)
633- t.block_map < - None ;
634589 t.commit < - Some (root, commit) ;
635590 Lwt. return_ok t
636591 with exn -> Lwt. return_error exn
0 commit comments