diff --git a/lib/Database.php b/lib/Database.php index 2323f5f..269d4c5 100644 --- a/lib/Database.php +++ b/lib/Database.php @@ -663,7 +663,6 @@ class Database { } public function feedUpdate($feedID, bool $throwError = false): bool { - $tr = $this->db->begin(); // check to make sure the feed exists if (!ValueInfo::id($feedID)) { throw new Db\ExceptionInput("typeViolation", ["action" => __FUNCTION__, "field" => "feed", 'id' => $feedID, 'type' => "int > 0"]); @@ -682,7 +681,6 @@ class Database { if (!$feed->modified) { // if the feed hasn't changed, just compute the next fetch time and record it $this->db->prepare("UPDATE arsse_feeds SET updated = CURRENT_TIMESTAMP, next_fetch = ? WHERE id is ?", 'datetime', 'int')->run($feed->nextFetch, $feedID); - $tr->commit(); return false; } } catch (Feed\Exception $e) { @@ -691,7 +689,6 @@ class Database { "UPDATE arsse_feeds SET updated = CURRENT_TIMESTAMP, next_fetch = ?, err_count = err_count + 1, err_msg = ? WHERE id is ?", 'datetime', 'str', 'int' )->run(Feed::nextFetchOnError($f['err_count']), $e->getMessage(), $feedID); - $tr->commit(); if ($throwError) { throw $e; } @@ -719,6 +716,7 @@ class Database { ); } // actually perform updates + $tr = $this->db->begin(); foreach ($feed->newItems as $article) { $articleID = $qInsertArticle->run( $article->url, diff --git a/lib/Db/SQLite3/Driver.php b/lib/Db/SQLite3/Driver.php index e4d5f1e..acf6e31 100644 --- a/lib/Db/SQLite3/Driver.php +++ b/lib/Db/SQLite3/Driver.php @@ -31,9 +31,11 @@ class Driver extends \JKingWeb\Arsse\Db\AbstractDriver { $timeout = Arsse::$conf->dbSQLite3Timeout * 1000; try { $this->db = $this->makeConnection($dbFile, $mode, Arsse::$conf->dbSQLite3Key); - // set initial options + // enable exceptions $this->db->enableExceptions(true); - $this->exec("PRAGMA journal_mode = wal"); + // set the timeout; parameters are not allowed for pragmas, but this usage should be safe + $this->exec("PRAGMA busy_timeout = $timeout"); + // set other initial options $this->exec("PRAGMA foreign_keys = yes"); } catch (\Throwable $e) { // if opening the database doesn't work, check various pre-conditions to find out what the problem might be @@ -56,8 +58,6 @@ class Driver extends \JKingWeb\Arsse\Db\AbstractDriver { // otherwise the database is probably corrupt throw new Exception("fileCorrupt", $dbFile); } - // finally set the timeout; parameters are not allowed for pragmas, but this usage should be safe - $this->exec("PRAGMA busy_timeout = $timeout"); } protected function makeConnection(string $file, int $opts, string $key) { diff --git a/sql/SQLite3/0.sql b/sql/SQLite3/0.sql index b69c295..e4cc5e4 100644 --- a/sql/SQLite3/0.sql +++ b/sql/SQLite3/0.sql @@ -2,6 +2,9 @@ -- Copyright 2017 J. King, Dustin Wilson et al. -- See LICENSE and AUTHORS files for details +-- Make the database WAL-journalled; this is persitent +PRAGMA journal_mode = wal; + -- metadata create table arsse_meta( key text primary key not null, -- metadata key