message: SQLiteBlockStore: Don't group put_block calls
  This is not a good idea with connection pooling.
diff: @@ -11,8 +11,6 @@ where
  {
  pool: r2d2::Pool<r2d2_sqlite::SqliteConnectionManager>,
  dummy: std::marker::PhantomData<B>,
  - in_txn: bool,
  - pending_changes: usize,
  }
  impl<B> SQLiteBlockStore<B>
  @@ -55,40 +53,19 @@ where
  )
  .unwrap();
  - SQLiteBlockStore {
  - pool,
  - dummy: std::marker::PhantomData,
  - in_txn: false,
  - pending_changes: 0,
  - }
  - }
  -
  - fn flush(&mut self) {
  - if self.in_txn {
  - //eprintln!("flushing sqlite...");
  - self.pool
  - .get()
  - .unwrap()
  - .execute("commit", rusqlite::NO_PARAMS)
  + /*
  + connection
  + .execute("pragma synchronous = off", rusqlite::NO_PARAMS)
  .unwrap();
  - self.in_txn = false;
  - }
  - }
  + */
  - fn do_change(&mut self) {
  - if self.in_txn {
  - self.pending_changes += 1;
  - if self.pending_changes > 100000 {
  - self.flush();
  - }
  - } else {
  - self.pool
  - .get()
  - .unwrap()
  - .execute("begin transaction", rusqlite::NO_PARAMS)
  + connection
  + .execute_batch("pragma journal_mode = WAL")
  .unwrap();
  - self.in_txn = true;
  - self.pending_changes = 1;
  +
  + SQLiteBlockStore {
  + pool,
  + dummy: std::marker::PhantomData,
  }
  }
  }
  @@ -97,15 +74,6 @@ fn blob_to_hash<Id: BlockId>(blob: Vec<u8>) -> Id {
  Id::deserialize(&blob[..]).unwrap()
  }
  -impl<B> Drop for SQLiteBlockStore<B>
  -where
  - B: Block,
  -{
  - fn drop(&mut self) {
  - self.flush();
  - }
  -}
  -
  impl<B> BlockStore for SQLiteBlockStore<B>
  where
  B: Block,
  @@ -113,13 +81,11 @@ where
  type Block = B;
  fn put_block_internal(&mut self, block: &B, block_info: BlockInfo<B::Id>) -> Result<(), Error> {
  - self.do_change();
  -
  - // FIXME: wrap the next two statements in a transaction
  + let mut conn = self.pool.get().unwrap();
  - let conn = self.pool.get().unwrap();
  + let tx = conn.transaction().unwrap();
  - conn.prepare_cached("insert into Blocks (hash, block) values(?, ?)")
  + tx.prepare_cached("insert into Blocks (hash, block) values(?, ?)")
  .unwrap()
  .execute(&[
  &block_info.block_hash.serialize_as_vec().unwrap()[..],
  @@ -142,7 +108,7 @@ where
  None => (Value::Null, Value::Null),
  };
  - conn
  + tx
  .prepare_cached("insert into BlockInfo (hash, depth, parent, fast_distance, fast_hash) values(?, ?, ?, ?, ?)")
  .unwrap()
  .execute(&[
  @@ -153,6 +119,8 @@ where
  fast_hash,
  ]).unwrap();
  + tx.commit().unwrap();
  +
  Ok(())
  }
  