Merge pull request #4782 from bendk/places-db-locked

Use BEGIN IMMEDIATE in `open_database`
This commit is contained in:
bendk 2022-02-01 10:43:02 -05:00 коммит произвёл GitHub
Родитель 76e4c8f039 7600260931
Коммит d5c490946e
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
2 изменённых файлов: 12 добавлений и 2 удалений

Просмотреть файл

@ -18,3 +18,10 @@ Use the template below to make assigning a version number during the release cut
- Description of the change with a link to the pull request ([#0000](https://github.com/mozilla/application-services/pull/0000))
-->
## Places
### What's Changed
- The database initialization code now uses BEGIN IMMIDIATE to start a
transaction. This will hopefully prevent `database is locked` errors when
opening a sync connection.

Просмотреть файл

@ -28,7 +28,10 @@
/// See the autofill DB code for an example.
///
use crate::ConnExt;
use rusqlite::{Connection, Error as RusqliteError, ErrorCode, OpenFlags, Transaction, NO_PARAMS};
use rusqlite::{
Connection, Error as RusqliteError, ErrorCode, OpenFlags, Transaction, TransactionBehavior,
NO_PARAMS,
};
use std::path::Path;
use thiserror::Error;
@ -113,7 +116,7 @@ fn do_open_database_with_flags<CI: ConnectionInitializer, P: AsRef<Path>>(
connection_initializer.prepare(&conn)?;
if open_flags.contains(OpenFlags::SQLITE_OPEN_READ_WRITE) {
let tx = conn.transaction()?;
let tx = conn.transaction_with_behavior(TransactionBehavior::Immediate)?;
if run_init {
log::debug!("{}: initializing new database", CI::NAME);
connection_initializer.init(&tx)?;