Allow db->set_timeout(null) to disable DB timeouts, see #874
This commit is contained in:
parent
9e52434480
commit
3bb1566df2
7 changed files with 13 additions and 12 deletions
|
@ -129,7 +129,7 @@ class Database
|
|||
$this->dbtime += $dur;
|
||||
}
|
||||
|
||||
public function set_timeout(int $time): void
|
||||
public function set_timeout(?int $time): void
|
||||
{
|
||||
$this->engine->set_timeout($this->db, $time);
|
||||
}
|
||||
|
|
|
@ -23,7 +23,7 @@ abstract class DBEngine
|
|||
return 'CREATE TABLE '.$name.' ('.$data.')';
|
||||
}
|
||||
|
||||
abstract public function set_timeout(PDO $db, int $time);
|
||||
abstract public function set_timeout(PDO $db, ?int $time);
|
||||
|
||||
abstract public function get_version(PDO $db): string;
|
||||
|
||||
|
@ -53,7 +53,7 @@ class MySQL extends DBEngine
|
|||
return 'CREATE TABLE '.$name.' ('.$data.') '.$ctes;
|
||||
}
|
||||
|
||||
public function set_timeout(PDO $db, int $time): void
|
||||
public function set_timeout(PDO $db, ?int $time): void
|
||||
{
|
||||
// These only apply to read-only queries, which appears to be the best we can to mysql-wise
|
||||
// $db->exec("SET SESSION MAX_EXECUTION_TIME=".$time.";");
|
||||
|
@ -98,8 +98,9 @@ class PostgreSQL extends DBEngine
|
|||
return "CREATE TABLE $name ($data)";
|
||||
}
|
||||
|
||||
public function set_timeout(PDO $db, int $time): void
|
||||
public function set_timeout(PDO $db, ?int $time): void
|
||||
{
|
||||
if(is_null($time)) $time = 0;
|
||||
$db->exec("SET statement_timeout TO ".$time.";");
|
||||
}
|
||||
|
||||
|
@ -210,7 +211,7 @@ class SQLite extends DBEngine
|
|||
return "CREATE TABLE $name ($cols_redone); $extras";
|
||||
}
|
||||
|
||||
public function set_timeout(PDO $db, int $time): void
|
||||
public function set_timeout(PDO $db, ?int $time): void
|
||||
{
|
||||
// There doesn't seem to be such a thing for SQLite, so it does nothing
|
||||
}
|
||||
|
|
|
@ -48,7 +48,7 @@ class AdminPage extends Extension
|
|||
if ($user->check_auth_token()) {
|
||||
log_info("admin", "Util: $action");
|
||||
set_time_limit(0);
|
||||
$database->set_timeout(300000);
|
||||
$database->set_timeout(null);
|
||||
send_event($aae);
|
||||
}
|
||||
|
||||
|
|
|
@ -77,14 +77,14 @@ class Approval extends Extension
|
|||
$approval_action = $_POST["approval_action"];
|
||||
switch ($approval_action) {
|
||||
case "approve_all":
|
||||
$database->set_timeout(300000); // These updates can take a little bit
|
||||
$database->set_timeout(null); // These updates can take a little bit
|
||||
$database->execute(
|
||||
"UPDATE images SET approved = :true, approved_by_id = :approved_by_id WHERE approved = :false",
|
||||
["approved_by_id"=>$user->id, "true"=>true, "false"=>false]
|
||||
);
|
||||
break;
|
||||
case "disapprove_all":
|
||||
$database->set_timeout(300000); // These updates can take a little bit
|
||||
$database->set_timeout(null); // These updates can take a little bit
|
||||
$database->execute(
|
||||
"UPDATE images SET approved = :false, approved_by_id = NULL WHERE approved = :true",
|
||||
["true"=>true, "false"=>false]
|
||||
|
|
|
@ -31,7 +31,7 @@ class MimeSystem extends Extension
|
|||
// them into one big transaction would not be a good idea.
|
||||
$database->commit();
|
||||
}
|
||||
$database->set_timeout(300000); // These updates can take a little bit
|
||||
$database->set_timeout(null); // These updates can take a little bit
|
||||
|
||||
$extensions = $database->get_col_iterable("SELECT DISTINCT ext FROM images");
|
||||
|
||||
|
|
|
@ -534,7 +534,7 @@ class Ratings extends Extension
|
|||
break;
|
||||
}
|
||||
|
||||
$database->set_timeout(300000); // These updates can take a little bit
|
||||
$database->set_timeout(null); // These updates can take a little bit
|
||||
|
||||
$database->execute("UPDATE images SET rating = :new WHERE rating = :old", ["new"=>'?', "old"=>'u' ]);
|
||||
|
||||
|
|
|
@ -11,7 +11,7 @@ class Upgrade extends Extension
|
|||
if ($event->cmd == "db-upgrade") {
|
||||
print("Running DB Upgrade\n");
|
||||
global $database;
|
||||
$database->set_timeout(300000); // These updates can take a little bit
|
||||
$database->set_timeout(null); // These updates can take a little bit
|
||||
send_event(new DatabaseUpgradeEvent());
|
||||
}
|
||||
}
|
||||
|
@ -156,7 +156,7 @@ class Upgrade extends Extension
|
|||
break;
|
||||
}
|
||||
|
||||
$database->set_timeout(300000); // These updates can take a little bit
|
||||
$database->set_timeout(null); // These updates can take a little bit
|
||||
|
||||
log_info("upgrade", "Setting index for ext column");
|
||||
$database->execute('CREATE INDEX images_ext_idx ON images(ext)');
|
||||
|
|
Reference in a new issue