use register to reclaim
This commit is contained in:
parent
be003bb5e6
commit
4dc6e2fb6a
3 changed files with 11 additions and 5 deletions
|
@ -12,6 +12,7 @@ use Utopia\Database\Database as UtopiaDatabase;
|
|||
use Utopia\Database\Document;
|
||||
use Utopia\Database\Validator\Authorization;
|
||||
use Utopia\Logger\Log;
|
||||
use Utopia\Registry\Registry;
|
||||
use Utopia\Validator\WhiteList;
|
||||
|
||||
Authorization::disable();
|
||||
|
@ -69,11 +70,11 @@ function aggregateTimeseries(UtopiaDatabase $database, InfluxDatabase $influxDB,
|
|||
}, $interval);
|
||||
}
|
||||
|
||||
function aggregateDatabase(UtopiaDatabase $database, callable $getProjectDB, callable $logError): void
|
||||
function aggregateDatabase(UtopiaDatabase $database, callable $getProjectDB, Registry $register, callable $logError): void
|
||||
{
|
||||
$interval = (int) App::getEnv('_APP_USAGE_DATABASE_INTERVAL', '900'); // 15 minutes (by default)
|
||||
$usage = new Database($database, $getProjectDB, $logError);
|
||||
$aggregrator = new Aggregator($database, $getProjectDB, $logError);
|
||||
$usage = new Database($database, $getProjectDB, $register, $logError);
|
||||
$aggregrator = new Aggregator($database, $getProjectDB, $register, $logError);
|
||||
|
||||
Console::loop(function () use ($interval, $usage, $aggregrator) {
|
||||
$now = date('d-m-Y H:i:s', time());
|
||||
|
@ -105,7 +106,7 @@ $cli
|
|||
aggregateTimeseries($database, $influxDB, $getProjectDB, $logError);
|
||||
break;
|
||||
case 'database':
|
||||
aggregateDatabase($database, $getProjectDB, $logError);
|
||||
aggregateDatabase($database, $getProjectDB, $register, $logError);
|
||||
break;
|
||||
default:
|
||||
Console::error("Unsupported usage aggregation type");
|
||||
|
|
|
@ -217,6 +217,7 @@ class Aggregator extends Database
|
|||
$this->aggregateDatabaseMetrics($database, $project);
|
||||
$this->aggregateStorageMetrics($database, $project);
|
||||
$this->aggregateUsersMetrics($database, $project);
|
||||
$this->register->get('pools')->reclaim();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
@ -10,9 +10,11 @@ use Utopia\Database\Document;
|
|||
use Utopia\Database\Exception\Authorization;
|
||||
use Utopia\Database\Exception\Structure;
|
||||
use Utopia\Database\Query;
|
||||
use Utopia\Registry\Registry;
|
||||
|
||||
class Database extends Calculator
|
||||
{
|
||||
protected Registry $register;
|
||||
protected array $periods = [
|
||||
[
|
||||
'key' => '30m',
|
||||
|
@ -24,8 +26,9 @@ class Database extends Calculator
|
|||
],
|
||||
];
|
||||
|
||||
public function __construct(UtopiaDatabase $database, callable $getProjectDB, callable $errorHandler = null)
|
||||
public function __construct(UtopiaDatabase $database, callable $getProjectDB, Registry $register, callable $errorHandler = null)
|
||||
{
|
||||
$this->register = $register;
|
||||
$this->database = $database;
|
||||
$this->getProjectDB = $getProjectDB;
|
||||
$this->errorHandler = $errorHandler;
|
||||
|
@ -359,6 +362,7 @@ class Database extends Calculator
|
|||
$this->usersStats($database, $project->getId());
|
||||
$this->databaseStats($database, $project);
|
||||
$this->storageStats($database, $project);
|
||||
$this->register->get('pools')->reclaim();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue