Allow db->set_timeout(null) to disable DB timeouts, see #874
This commit is contained in:
parent
9e52434480
commit
3bb1566df2
@ -129,7 +129,7 @@ class Database
|
|||||||
$this->dbtime += $dur;
|
$this->dbtime += $dur;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function set_timeout(int $time): void
|
public function set_timeout(?int $time): void
|
||||||
{
|
{
|
||||||
$this->engine->set_timeout($this->db, $time);
|
$this->engine->set_timeout($this->db, $time);
|
||||||
}
|
}
|
||||||
|
@ -23,7 +23,7 @@ abstract class DBEngine
|
|||||||
return 'CREATE TABLE '.$name.' ('.$data.')';
|
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;
|
abstract public function get_version(PDO $db): string;
|
||||||
|
|
||||||
@ -53,7 +53,7 @@ class MySQL extends DBEngine
|
|||||||
return 'CREATE TABLE '.$name.' ('.$data.') '.$ctes;
|
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
|
// 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.";");
|
// $db->exec("SET SESSION MAX_EXECUTION_TIME=".$time.";");
|
||||||
@ -98,8 +98,9 @@ class PostgreSQL extends DBEngine
|
|||||||
return "CREATE TABLE $name ($data)";
|
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.";");
|
$db->exec("SET statement_timeout TO ".$time.";");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -210,7 +211,7 @@ class SQLite extends DBEngine
|
|||||||
return "CREATE TABLE $name ($cols_redone); $extras";
|
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
|
// 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()) {
|
if ($user->check_auth_token()) {
|
||||||
log_info("admin", "Util: $action");
|
log_info("admin", "Util: $action");
|
||||||
set_time_limit(0);
|
set_time_limit(0);
|
||||||
$database->set_timeout(300000);
|
$database->set_timeout(null);
|
||||||
send_event($aae);
|
send_event($aae);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -77,14 +77,14 @@ class Approval extends Extension
|
|||||||
$approval_action = $_POST["approval_action"];
|
$approval_action = $_POST["approval_action"];
|
||||||
switch ($approval_action) {
|
switch ($approval_action) {
|
||||||
case "approve_all":
|
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(
|
$database->execute(
|
||||||
"UPDATE images SET approved = :true, approved_by_id = :approved_by_id WHERE approved = :false",
|
"UPDATE images SET approved = :true, approved_by_id = :approved_by_id WHERE approved = :false",
|
||||||
["approved_by_id"=>$user->id, "true"=>true, "false"=>false]
|
["approved_by_id"=>$user->id, "true"=>true, "false"=>false]
|
||||||
);
|
);
|
||||||
break;
|
break;
|
||||||
case "disapprove_all":
|
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(
|
$database->execute(
|
||||||
"UPDATE images SET approved = :false, approved_by_id = NULL WHERE approved = :true",
|
"UPDATE images SET approved = :false, approved_by_id = NULL WHERE approved = :true",
|
||||||
["true"=>true, "false"=>false]
|
["true"=>true, "false"=>false]
|
||||||
|
@ -31,7 +31,7 @@ class MimeSystem extends Extension
|
|||||||
// them into one big transaction would not be a good idea.
|
// them into one big transaction would not be a good idea.
|
||||||
$database->commit();
|
$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");
|
$extensions = $database->get_col_iterable("SELECT DISTINCT ext FROM images");
|
||||||
|
|
||||||
|
@ -534,7 +534,7 @@ class Ratings extends Extension
|
|||||||
break;
|
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' ]);
|
$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") {
|
if ($event->cmd == "db-upgrade") {
|
||||||
print("Running DB Upgrade\n");
|
print("Running DB Upgrade\n");
|
||||||
global $database;
|
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());
|
send_event(new DatabaseUpgradeEvent());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -156,7 +156,7 @@ class Upgrade extends Extension
|
|||||||
break;
|
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");
|
log_info("upgrade", "Setting index for ext column");
|
||||||
$database->execute('CREATE INDEX images_ext_idx ON images(ext)');
|
$database->execute('CREATE INDEX images_ext_idx ON images(ext)');
|
||||||
|
Loading…
x
Reference in New Issue
Block a user