Improve live DB clone speed
This commit is contained in:
@@ -27,14 +27,32 @@ if (isset($_ENV['USE_ENV']) && $_ENV['USE_ENV'] === 'true') {
|
||||
'REDIS_CONFIG_DATABASE' => 'database',
|
||||
'REDIS_CONFIG_PASSWORD' => 'password'
|
||||
];
|
||||
$dbTarget = strtolower(trim((string)($_ENV['CONFIG_DB_TARGET'] ?? 'live')));
|
||||
if ($dbTarget !== 'live' && $dbTarget !== 'debug') {
|
||||
$dbTarget = 'live';
|
||||
}
|
||||
|
||||
$resolveDbValue = function (string $key) use ($dbTarget): string {
|
||||
$liveKey = 'CONFIG_DB_' . $key;
|
||||
$debugKey = 'CONFIG_DB_DEBUG_' . $key;
|
||||
$liveValue = (string)($_ENV[$liveKey] ?? '');
|
||||
$debugValue = (string)($_ENV[$debugKey] ?? '');
|
||||
|
||||
if ($dbTarget === 'debug' && $debugValue !== '') {
|
||||
return $debugValue;
|
||||
}
|
||||
|
||||
return $liveValue;
|
||||
};
|
||||
|
||||
/**
|
||||
* Set the db configuration
|
||||
* Set the db configuration from selected target (live/debug)
|
||||
*/
|
||||
$CONFIG_DB = [
|
||||
'host' => $_ENV['CONFIG_DB_HOST'],
|
||||
'user' => $_ENV['CONFIG_DB_USER'],
|
||||
'password' => $_ENV['CONFIG_DB_PASSWORD'],
|
||||
'database' => $_ENV['CONFIG_DB_DATABASE']
|
||||
'host' => $resolveDbValue('HOST'),
|
||||
'user' => $resolveDbValue('USER'),
|
||||
'password' => $resolveDbValue('PASSWORD'),
|
||||
'database' => $resolveDbValue('DATABASE')
|
||||
];
|
||||
/**
|
||||
* Set the debug configuration
|
||||
@@ -98,4 +116,4 @@ if (isset($_ENV['USE_ENV']) && $_ENV['USE_ENV'] === 'true') {
|
||||
} else {
|
||||
// Throw an error if the environment variables are not set
|
||||
throw new Exception('Environment variables are not set');
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user