mirror of
https://code.mensbeam.com/MensBeam/Arsse.git
synced 2024-12-22 13:12:41 +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 {
|
||||
$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,
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue