mirror of
https://github.com/appwrite/appwrite
synced 2026-05-24 09:28:40 +00:00
Filter in prepare
This commit is contained in:
parent
6dbc8c5464
commit
3fe1147194
1 changed files with 11 additions and 8 deletions
|
|
@ -8,7 +8,7 @@ use Utopia\Queue\Publisher;
|
||||||
class StatsUsage extends Event
|
class StatsUsage extends Event
|
||||||
{
|
{
|
||||||
protected array $metrics = [];
|
protected array $metrics = [];
|
||||||
protected array $reduce = [];
|
protected array $reduce = [];
|
||||||
protected array $disabled = [];
|
protected array $disabled = [];
|
||||||
|
|
||||||
public function __construct(protected Publisher $publisher)
|
public function __construct(protected Publisher $publisher)
|
||||||
|
|
@ -42,10 +42,6 @@ class StatsUsage extends Event
|
||||||
*/
|
*/
|
||||||
public function addMetric(string $key, int $value): self
|
public function addMetric(string $key, int $value): self
|
||||||
{
|
{
|
||||||
if ($this->disabled[$key]) {
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->metrics[] = [
|
$this->metrics[] = [
|
||||||
'key' => $key,
|
'key' => $key,
|
||||||
'value' => $value,
|
'value' => $value,
|
||||||
|
|
@ -62,7 +58,7 @@ class StatsUsage extends Event
|
||||||
*/
|
*/
|
||||||
public function disableMetric(string $key): self
|
public function disableMetric(string $key): self
|
||||||
{
|
{
|
||||||
$this->disabled[$key] = true;
|
$this->disabled[] = $key;
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
@ -76,8 +72,15 @@ class StatsUsage extends Event
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
'project' => $this->getProject(),
|
'project' => $this->getProject(),
|
||||||
'reduce' => $this->reduce,
|
'reduce' => $this->reduce,
|
||||||
'metrics' => $this->metrics,
|
'metrics' => \array_filter($this->metrics, function ($metric) {
|
||||||
|
foreach (array_keys($this->disabled) as $disabledMetric) {
|
||||||
|
if (\str_ends_with($metric['key'], $disabledMetric)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}),
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue