···180180 Set.empty
181181 |> Set.to_list |> Lwt.return
182182183183-let list_records t collection : (string * Cid.t * record) list Lwt.t =
183183+let list_all_records t collection : (string * Cid.t * record) list Lwt.t =
184184 let%lwt map = get_map t in
185185 StringMap.bindings map
186186 |> List.filter (fun (path, _) ->
···436436 Lwt.return {commit= new_commit; results}
437437438438let load did : t Lwt.t =
439439- let%lwt data_store_conn =
440440- Util.connect_sqlite Util.Constants.pegasus_db_location
441441- in
442442- let%lwt user_db = Util.connect_sqlite (Util.Constants.user_db_location did) in
439439+ let%lwt data_store_conn = Data_store.connect () in
440440+ let%lwt user_db = User_store.connect did in
443441 let%lwt () = User_store.init user_db in
444442 let%lwt {signing_key; _} =
445443 match%lwt Data_store.get_actor_by_identifier did data_store_conn with
+26-7
pegasus/lib/user_store.ml
···150150 data BLOB NOT NULL
151151 );
152152 CREATE INDEX IF NOT EXISTS records_cid_idx ON records (cid);
153153+ CREATE INDEX IF NOT EXISTS records_since_idx ON records (since);
153154 |sql}]
154155 ()
155156···168169 get_many
169170 {sql| SELECT @string{path}, @CID{cid}, @Blob{data}, @string{since} FROM records
170171 WHERE path LIKE %string{collection}/%
171171- ORDER BY since DESC LIMIT %int{limit} OFFSET %int{offset}
172172+ AND since < %string{cursor}
173173+ ORDER BY since DESC LIMIT %int{limit}
174174+ |sql}]
175175+176176+ let list_records_reverse =
177177+ [%rapper
178178+ get_many
179179+ {sql| SELECT @string{path}, @CID{cid}, @Blob{data}, @string{since} FROM records
180180+ WHERE path LIKE %string{collection}/%
181181+ AND since > %string{cursor}
182182+ ORDER BY since ASC LIMIT %int{limit}
172183 |sql}]
173184174185 let put_record =
···260271 let clear_blob_refs path cids =
261272 [%rapper
262273 execute
263263- {sql| DELETE FROM blobs_records WHERE record_path LIKE %string{path} AND blob_id IN (
264264- SELECT id FROM blobs WHERE cid IN (%list{%CID{cids}})
265265- )
274274+ {sql| DELETE FROM blobs_records
275275+ WHERE record_path LIKE %string{path}
276276+ AND blob_id IN (
277277+ SELECT id FROM blobs WHERE cid IN (%list{%CID{cids}})
278278+ )
266279 |sql}]
267280 ~path ~cids
268281end
269282270283type t = (module Rapper_helper.CONNECTION)
284284+285285+let connect did : t Lwt.t =
286286+ Util.connect_sqlite (Util.Constants.user_db_location did)
271287272288let init conn : unit Lwt.t =
273289 let$! () = Queries.create_blocks_tables conn in
···348364 {path; cid; value= Lex.of_cbor data; since} )
349365 >>= Lwt.return
350366351351-let list_records conn ?(limit = 100) ?(offset = 0) collection :
352352- record list Lwt.t =
353353- Queries.list_records ~collection ~limit ~offset conn
367367+let list_records conn ?(limit = 100) ?(cursor = "") ?(reverse = false)
368368+ collection : record list Lwt.t =
369369+ let fn =
370370+ if reverse then Queries.list_records_reverse else Queries.list_records
371371+ in
372372+ fn ~collection ~limit ~cursor conn
354373 >$! List.map (fun (path, cid, data, since) ->
355374 {path; cid; value= Lex.of_cbor data; since} )
356375 >>= Lwt.return
+10
pegasus/lib/xrpc.ml
···2323 | Error e ->
2424 exn_to_response e
25252626+let parse_query (req : Dream.request)
2727+ (of_yojson : Yojson.Safe.t -> ('a, string) result) : 'a Lwt.t =
2828+ try%lwt
2929+ let queries = Dream.all_queries req in
3030+ let query_json =
3131+ `Assoc (List.map (fun (k, v) -> (k, Yojson.Safe.from_string v)) queries)
3232+ in
3333+ query_json |> of_yojson |> Result.get_ok |> Lwt.return
3434+ with _ -> Errors.invalid_request "Invalid query string"
3535+2636let parse_body (req : Dream.request)
2737 (of_yojson : Yojson.Safe.t -> ('a, string) result) : 'a Lwt.t =
2838 try%lwt