mirror of
https://we.phorge.it/source/phorge.git
synced 2024-12-21 21:10:56 +01:00
Fix connection retry code to actually retry connections, instead of reading the
dead connection out of the connection cache. Summary: Test Plan: Reviewers: CC:
This commit is contained in:
parent
21650c47b6
commit
cf22d8c6cb
2 changed files with 22 additions and 5 deletions
|
@ -87,14 +87,31 @@ class AphrontMySQLDatabaseConnection extends AphrontDatabaseConnection {
|
||||||
return idx($this->configuration, $key, $default);
|
return idx($this->configuration, $key, $default);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private function closeConnection() {
|
||||||
|
if ($this->connection) {
|
||||||
|
$this->connection = null;
|
||||||
|
$key = $this->getConnectionCacheKey();
|
||||||
|
unset(self::$connectionCache[$key]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private function getConnectionCacheKey() {
|
||||||
|
$user = $this->getConfiguration('user');
|
||||||
|
$host = $this->getConfiguration('host');
|
||||||
|
$database = $this->getConfiguration('database');
|
||||||
|
|
||||||
|
return "{$user}:{$host}:{$database}";
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
private function establishConnection() {
|
private function establishConnection() {
|
||||||
$this->connection = null;
|
$this->closeConnection();
|
||||||
|
|
||||||
$user = $this->getConfiguration('user');
|
$user = $this->getConfiguration('user');
|
||||||
$host = $this->getConfiguration('host');
|
$host = $this->getConfiguration('host');
|
||||||
$database = $this->getConfiguration('database');
|
$database = $this->getConfiguration('database');
|
||||||
|
|
||||||
$key = "{$user}:{$host}:{$database}";
|
$key = $this->getConnectionCacheKey();
|
||||||
if (isset(self::$connectionCache[$key])) {
|
if (isset(self::$connectionCache[$key])) {
|
||||||
$this->connection = self::$connectionCache[$key];
|
$this->connection = self::$connectionCache[$key];
|
||||||
return;
|
return;
|
||||||
|
@ -176,7 +193,7 @@ class AphrontMySQLDatabaseConnection extends AphrontDatabaseConnection {
|
||||||
$this->requireConnection();
|
$this->requireConnection();
|
||||||
|
|
||||||
$start = microtime(true);
|
$start = microtime(true);
|
||||||
$result = mysql_query($raw_query, $this->connection);
|
$result = @mysql_query($raw_query, $this->connection);
|
||||||
$end = microtime(true);
|
$end = microtime(true);
|
||||||
|
|
||||||
DarkConsoleServicesPluginAPI::addEvent(
|
DarkConsoleServicesPluginAPI::addEvent(
|
||||||
|
@ -200,7 +217,7 @@ class AphrontMySQLDatabaseConnection extends AphrontDatabaseConnection {
|
||||||
if ($this->isInsideTransaction()) {
|
if ($this->isInsideTransaction()) {
|
||||||
throw $ex;
|
throw $ex;
|
||||||
}
|
}
|
||||||
$this->connection = null;
|
$this->closeConnection();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue