[sql] batch write of attributes

Summary:
Instead of many successive implicit transactions to write each
attributes of the procedures in a file, write them all in a single
transaction.

Reviewed By: jberdine

Differential Revision: D10173351

fbshipit-source-id: 5f2a5ffb5
master
Jules Villard 6 years ago committed by Facebook Github Bot
parent 96cbdb15c7
commit e3efc0e465

@ -52,7 +52,8 @@ let add source_file cfg tenv =
(* NOTE: it's important to write attribute files to disk before writing cfgs to disk.
OndemandCapture module relies on it - it uses existance of the cfg as a barrier to make
sure that all attributes were written to disk (but not necessarily flushed) *)
Cfg.save_attributes source_file cfg ;
SqliteUtils.with_transaction (ResultsDatabase.get_database ()) ~f:(fun () ->
Cfg.save_attributes source_file cfg ) ;
ResultsDatabase.with_registered_statement store_statement ~f:(fun db store_stmt ->
SourceFile.SQLite.serialize source_file
|> Sqlite3.bind store_stmt 1

@ -95,6 +95,12 @@ let db_close db =
(Sqlite3.errmsg db)))
let with_transaction db ~f =
exec db ~log:"begin transaction" ~stmt:"BEGIN IMMEDIATE TRANSACTION" ;
f () ;
exec db ~log:"commit transaction" ~stmt:"COMMIT"
module type Data = sig
type t

@ -60,6 +60,9 @@ val result_unit : ?finalize:bool -> Sqlite3.db -> log:string -> Sqlite3.stmt ->
val db_close : Sqlite3.db -> unit
(** Close the given database and asserts that it was effective. Raises {!Error} if not. *)
val with_transaction : Sqlite3.db -> f:(unit -> unit) -> unit
(** Execute [f] within an explicit sqlite transaction. *)
(** An API commonly needed to store and retrieve objects from the database *)
module type Data = sig
type t

Loading…
Cancel
Save