objective categorical abstract machine language personal data server
65
fork

Configure Feed

Select the types of activity you want to include in your feed.

Don't pass empty lists to ppx_rapper

futurGH a4c135cf 8ee9a143

+33 -20
+8 -4
pegasus/lib/repository.ml
··· 326 326 Util.find_blob_refs record.value 327 327 |> List.map (fun (r : Mist.Blob_ref.t) -> r.ref) 328 328 in 329 - let%lwt () = User_store.clear_blob_refs t.db path refs in 330 - Lwt.return_unit 329 + if not (List.is_empty refs) then 330 + let%lwt () = User_store.clear_blob_refs t.db path refs in 331 + Lwt.return_unit 332 + else Lwt.return_unit 331 333 | None -> 332 334 Lwt.return_unit ) 333 335 | None -> ··· 371 373 Util.find_blob_refs record.value 372 374 |> List.map (fun (r : Mist.Blob_ref.t) -> r.ref) 373 375 in 374 - let%lwt () = User_store.clear_blob_refs t.db path refs in 375 - Lwt.return_unit 376 + if not (List.is_empty refs) then 377 + let%lwt () = User_store.clear_blob_refs t.db path refs in 378 + Lwt.return_unit 379 + else Lwt.return_unit 376 380 | None -> 377 381 Lwt.return_unit 378 382 in
+25 -16
pegasus/lib/user_store.ml
··· 319 319 >|= function Some {data; _} -> Some data | None -> None 320 320 321 321 let get_blocks t cids : Block_map.with_missing Lwt.t = 322 - let%lwt blocks = Util.use_pool t.db @@ Queries.get_blocks cids in 323 - Lwt.return 324 - (List.fold_left 325 - (fun (acc : Block_map.with_missing) cid -> 326 - match List.find_opt (fun (b : block) -> b.cid = cid) blocks with 327 - | Some {data; _} -> 328 - {acc with blocks= Block_map.set cid data acc.blocks} 329 - | None -> 330 - {acc with missing= cid :: acc.missing} ) 331 - {blocks= Block_map.empty; missing= []} 332 - cids ) 322 + if List.is_empty cids then 323 + Lwt.return ({blocks= Block_map.empty; missing= []} : Block_map.with_missing) 324 + else 325 + let%lwt blocks = Util.use_pool t.db @@ Queries.get_blocks cids in 326 + Lwt.return 327 + (List.fold_left 328 + (fun (acc : Block_map.with_missing) cid -> 329 + match List.find_opt (fun (b : block) -> b.cid = cid) blocks with 330 + | Some {data; _} -> 331 + {acc with blocks= Block_map.set cid data acc.blocks} 332 + | None -> 333 + {acc with missing= cid :: acc.missing} ) 334 + {blocks= Block_map.empty; missing= []} 335 + cids ) 333 336 334 337 let has t cid : bool Lwt.t = 335 338 Util.use_pool t.db @@ Queries.has_block cid ··· 438 441 (Util.Constants.user_blobs_location t.did) 439 442 (Cid.to_string cid) 440 443 in 441 - let () = Util.mkfile_p file ~perm:0o644 in 444 + let _ = 445 + Core_unix.openfile ~mode:[O_CREAT; O_WRONLY] file 446 + |> Core_unix.single_write ~buf:data 447 + in 442 448 let _ = Out_channel.with_open_bin file Out_channel.output_bytes data in 443 449 Util.use_pool t.db @@ Queries.put_blob cid mimetype 444 450 ··· 449 455 Util.use_pool t.db @@ Queries.put_blob_ref path cid 450 456 451 457 let put_blob_refs t path cids : (unit, exn) Lwt_result.t = 452 - Lwt_result.map (fun _ -> ()) 453 - @@ Util.multi_query t.db 454 - (List.map (fun cid -> Queries.put_blob_ref cid path) cids) 458 + if List.is_empty cids then Lwt.return_ok () 459 + else 460 + Lwt_result.map (fun _ -> ()) 461 + @@ Util.multi_query t.db 462 + (List.map (fun cid -> Queries.put_blob_ref cid path) cids) 455 463 456 464 let clear_blob_refs t path cids : unit Lwt.t = 457 - Util.use_pool t.db @@ Queries.clear_blob_refs path cids 465 + if List.is_empty cids then Lwt.return_unit 466 + else Util.use_pool t.db @@ Queries.clear_blob_refs path cids