Added set_timeout to database and engine
This commit is contained in:
parent
702f098ea6
commit
3efa76c6a2
@ -178,6 +178,11 @@ class Database
|
|||||||
$this->dbtime += $dur;
|
$this->dbtime += $dur;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function set_timeout(int $time): void
|
||||||
|
{
|
||||||
|
$this->engine->set_timeout($this->db, $time);
|
||||||
|
}
|
||||||
|
|
||||||
public function execute(string $query, array $args=[], bool $scoreql = false): PDOStatement
|
public function execute(string $query, array $args=[], bool $scoreql = false): PDOStatement
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
|
@ -12,7 +12,7 @@ abstract class SCORE
|
|||||||
const ILIKE = "SCORE_ILIKE";
|
const ILIKE = "SCORE_ILIKE";
|
||||||
}
|
}
|
||||||
|
|
||||||
class DBEngine
|
abstract class DBEngine
|
||||||
{
|
{
|
||||||
/** @var null|string */
|
/** @var null|string */
|
||||||
public $name = null;
|
public $name = null;
|
||||||
@ -33,6 +33,8 @@ class DBEngine
|
|||||||
{
|
{
|
||||||
return 'CREATE TABLE '.$name.' ('.$data.')';
|
return 'CREATE TABLE '.$name.' ('.$data.')';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public abstract function set_timeout(PDO $db, int $time);
|
||||||
}
|
}
|
||||||
|
|
||||||
class MySQL extends DBEngine
|
class MySQL extends DBEngine
|
||||||
@ -68,6 +70,13 @@ class MySQL extends DBEngine
|
|||||||
$ctes = "ENGINE=InnoDB DEFAULT CHARSET='utf8'";
|
$ctes = "ENGINE=InnoDB DEFAULT CHARSET='utf8'";
|
||||||
return 'CREATE TABLE '.$name.' ('.$data.') '.$ctes;
|
return 'CREATE TABLE '.$name.' ('.$data.') '.$ctes;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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.";");
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
class PostgreSQL extends DBEngine
|
class PostgreSQL extends DBEngine
|
||||||
@ -87,7 +96,7 @@ class PostgreSQL extends DBEngine
|
|||||||
} else {
|
} else {
|
||||||
$db->exec("SET application_name TO 'shimmie [local]';");
|
$db->exec("SET application_name TO 'shimmie [local]';");
|
||||||
}
|
}
|
||||||
$db->exec("SET statement_timeout TO ".DATABASE_TIMEOUT.";");
|
$this->set_timeout($db, DATABASE_TIMEOUT);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function scoreql_to_sql(string $data): string
|
public function scoreql_to_sql(string $data): string
|
||||||
@ -109,6 +118,12 @@ class PostgreSQL extends DBEngine
|
|||||||
$data = $this->scoreql_to_sql($data);
|
$data = $this->scoreql_to_sql($data);
|
||||||
return "CREATE TABLE $name ($data)";
|
return "CREATE TABLE $name ($data)";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function set_timeout(PDO $db, int $time): void
|
||||||
|
{
|
||||||
|
$db->exec("SET statement_timeout TO ".$time.";");
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// shimmie functions for export to sqlite
|
// shimmie functions for export to sqlite
|
||||||
@ -213,4 +228,9 @@ class SQLite extends DBEngine
|
|||||||
$cols_redone = implode(", ", $cols);
|
$cols_redone = implode(", ", $cols);
|
||||||
return "CREATE TABLE $name ($cols_redone); $extras";
|
return "CREATE TABLE $name ($cols_redone); $extras";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function set_timeout(PDO $db, int $time): void
|
||||||
|
{
|
||||||
|
// There doesn't seem to be such a thing for SQLite, so it does nothing
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1049,9 +1049,7 @@ class Media extends Extension
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($database->get_driver_name()==DatabaseDriver::PGSQL) { // These updates can take a little bit
|
$database->set_timeout(300000); // These updates can take a little bit
|
||||||
$database->execute("SET statement_timeout TO 300000;");
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($database->transaction === true) {
|
if ($database->transaction === true) {
|
||||||
$database->commit(); // Each of these commands could hit a lot of data, combining them into one big transaction would not be a good idea.
|
$database->commit(); // Each of these commands could hit a lot of data, combining them into one big transaction would not be a good idea.
|
||||||
|
@ -578,9 +578,7 @@ class Ratings extends Extension
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($database->get_driver_name()==DatabaseDriver::PGSQL) { // These updates can take a little bit
|
$database->set_timeout(300000); // These updates can take a little bit
|
||||||
$database->execute("SET statement_timeout TO 300000;");
|
|
||||||
}
|
|
||||||
|
|
||||||
$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' ]);
|
||||||
|
|
||||||
|
@ -71,9 +71,7 @@ class Rule34 extends Extension
|
|||||||
{
|
{
|
||||||
global $database, $page, $user;
|
global $database, $page, $user;
|
||||||
|
|
||||||
if ($user->can(Permissions::DELETE_USER)) { // deleting users can take a while
|
$database->set_timeout(DATABASE_TIMEOUT+15000); // deleting users can take a while
|
||||||
$database->execute("SET statement_timeout TO ".(DATABASE_TIMEOUT+15000).";");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (function_exists("sd_notify_watchdog")) {
|
if (function_exists("sd_notify_watchdog")) {
|
||||||
sd_notify_watchdog();
|
sd_notify_watchdog();
|
||||||
|
@ -191,9 +191,7 @@ class Upgrade extends Extension
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($database->get_driver_name()==DatabaseDriver::PGSQL) { // These updates can take a little bit
|
$database->set_timeout(300000); // These updates can take a little bit
|
||||||
$database->execute("SET statement_timeout TO 300000;");
|
|
||||||
}
|
|
||||||
|
|
||||||
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