mirror of
https://code.mensbeam.com/MensBeam/Arsse.git
synced 2024-12-23 05:44:53 +00:00
SQLite concurrency tweaks; fixes #131
This commit is contained in:
parent
a97072d1f2
commit
821bb22a72
3 changed files with 8 additions and 7 deletions
|
@ -663,7 +663,6 @@ class Database {
|
||||||
}
|
}
|
||||||
|
|
||||||
public function feedUpdate($feedID, bool $throwError = false): bool {
|
public function feedUpdate($feedID, bool $throwError = false): bool {
|
||||||
$tr = $this->db->begin();
|
|
||||||
// check to make sure the feed exists
|
// check to make sure the feed exists
|
||||||
if (!ValueInfo::id($feedID)) {
|
if (!ValueInfo::id($feedID)) {
|
||||||
throw new Db\ExceptionInput("typeViolation", ["action" => __FUNCTION__, "field" => "feed", 'id' => $feedID, 'type' => "int > 0"]);
|
throw new Db\ExceptionInput("typeViolation", ["action" => __FUNCTION__, "field" => "feed", 'id' => $feedID, 'type' => "int > 0"]);
|
||||||
|
@ -682,7 +681,6 @@ class Database {
|
||||||
if (!$feed->modified) {
|
if (!$feed->modified) {
|
||||||
// if the feed hasn't changed, just compute the next fetch time and record it
|
// 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);
|
$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;
|
return false;
|
||||||
}
|
}
|
||||||
} catch (Feed\Exception $e) {
|
} 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 ?",
|
"UPDATE arsse_feeds SET updated = CURRENT_TIMESTAMP, next_fetch = ?, err_count = err_count + 1, err_msg = ? WHERE id is ?",
|
||||||
'datetime', 'str', 'int'
|
'datetime', 'str', 'int'
|
||||||
)->run(Feed::nextFetchOnError($f['err_count']), $e->getMessage(), $feedID);
|
)->run(Feed::nextFetchOnError($f['err_count']), $e->getMessage(), $feedID);
|
||||||
$tr->commit();
|
|
||||||
if ($throwError) {
|
if ($throwError) {
|
||||||
throw $e;
|
throw $e;
|
||||||
}
|
}
|
||||||
|
@ -719,6 +716,7 @@ class Database {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
// actually perform updates
|
// actually perform updates
|
||||||
|
$tr = $this->db->begin();
|
||||||
foreach ($feed->newItems as $article) {
|
foreach ($feed->newItems as $article) {
|
||||||
$articleID = $qInsertArticle->run(
|
$articleID = $qInsertArticle->run(
|
||||||
$article->url,
|
$article->url,
|
||||||
|
|
|
@ -31,9 +31,11 @@ class Driver extends \JKingWeb\Arsse\Db\AbstractDriver {
|
||||||
$timeout = Arsse::$conf->dbSQLite3Timeout * 1000;
|
$timeout = Arsse::$conf->dbSQLite3Timeout * 1000;
|
||||||
try {
|
try {
|
||||||
$this->db = $this->makeConnection($dbFile, $mode, Arsse::$conf->dbSQLite3Key);
|
$this->db = $this->makeConnection($dbFile, $mode, Arsse::$conf->dbSQLite3Key);
|
||||||
// set initial options
|
// enable exceptions
|
||||||
$this->db->enableExceptions(true);
|
$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");
|
$this->exec("PRAGMA foreign_keys = yes");
|
||||||
} catch (\Throwable $e) {
|
} catch (\Throwable $e) {
|
||||||
// if opening the database doesn't work, check various pre-conditions to find out what the problem might be
|
// 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
|
// otherwise the database is probably corrupt
|
||||||
throw new Exception("fileCorrupt", $dbFile);
|
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) {
|
protected function makeConnection(string $file, int $opts, string $key) {
|
||||||
|
|
|
@ -2,6 +2,9 @@
|
||||||
-- Copyright 2017 J. King, Dustin Wilson et al.
|
-- Copyright 2017 J. King, Dustin Wilson et al.
|
||||||
-- See LICENSE and AUTHORS files for details
|
-- See LICENSE and AUTHORS files for details
|
||||||
|
|
||||||
|
-- Make the database WAL-journalled; this is persitent
|
||||||
|
PRAGMA journal_mode = wal;
|
||||||
|
|
||||||
-- metadata
|
-- metadata
|
||||||
create table arsse_meta(
|
create table arsse_meta(
|
||||||
key text primary key not null, -- metadata key
|
key text primary key not null, -- metadata key
|
||||||
|
|
Loading…
Reference in a new issue