diff --git a/CHANGELOG.md b/CHANGELOG.md index c1bc762..34b7098 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Fixed +- On Postgres, a write no longer waits for the database server's disk. A scan read about one feed a second and now reads 1,500 in 20 seconds. - Checking every feed no longer makes every icon in the feed list flash while it runs: the list keeps the icons it has already drawn. ### Security diff --git a/src/db.rs b/src/db.rs index 0d38cd5..4fe15b2 100644 --- a/src/db.rs +++ b/src/db.rs @@ -125,6 +125,12 @@ async fn connect(location: &str) -> Result { // 52ms, and 39s to subscribe an admin to 1,500 feeds (#135). A crash of ipx loses nothing; // only a power cut can lose the last transactions, and it never corrupts the file. opts.map_sqlx_sqlite_opts(|o| o.synchronous(sea_orm::sqlx::sqlite::SqliteSynchronous::Normal)); + // The same on Postgres, for ipx's own sessions: a commit waited for the WAL to reach the + // disk, 12.8ms on the databases project's server, and at about fifty commits a feed a scan + // took most of a second a feed (#140). A crash of the Postgres server can lose the last + // commits, about the last 0.6s, and never corrupts anything. Added to whatever options the + // URL sets, so it holds for the tests' search_path too. + opts.map_sqlx_postgres_opts(|o| o.options([("synchronous_commit", "off")])); sea_orm::Database::connect(opts) .await .with_context(|| format!("opening {}", redact(location))) @@ -2106,13 +2112,16 @@ mod tests { use super::*; #[tokio::test] - async fn sqlite_syncs_at_checkpoints_not_every_commit() { + async fn a_commit_does_not_wait_for_the_disk() { let db = Db::memory().await.unwrap(); - if db.orm.get_database_backend() != sea_orm::DbBackend::Sqlite { - return; + let backend = db.orm.get_database_backend(); + if backend == sea_orm::DbBackend::Sqlite { + let row = db.orm.query_one_raw(Statement::from_string(backend, "PRAGMA synchronous")).await.unwrap(); + assert_eq!(row.unwrap().try_get_by_index::(0).unwrap(), 1, "NORMAL, on every connection in the pool (#135)"); + } else { + let row = db.orm.query_one_raw(Statement::from_string(backend, "SHOW synchronous_commit")).await.unwrap(); + assert_eq!(row.unwrap().try_get_by_index::(0).unwrap(), "off", "with the test's own search_path as well (#140)"); } - let row = db.orm.query_one_raw(Statement::from_string(sea_orm::DbBackend::Sqlite, "PRAGMA synchronous")).await.unwrap(); - assert_eq!(row.unwrap().try_get_by_index::(0).unwrap(), 1, "NORMAL, on every connection in the pool (#135)"); } #[tokio::test]