mirror of
https://github.com/appwrite/appwrite
synced 2026-05-24 09:28:40 +00:00
sort and hardcode bachSize
This commit is contained in:
parent
95f49559d0
commit
de9e177bc8
1 changed files with 17 additions and 5 deletions
|
|
@ -206,8 +206,6 @@ class StatsResources extends Action
|
||||||
$this->writeDocuments($dbForLogs, $project);
|
$this->writeDocuments($dbForLogs, $project);
|
||||||
} catch (Throwable $th) {
|
} catch (Throwable $th) {
|
||||||
call_user_func_array($this->logError, [$th, "StatsResources", "count_for_project_{$project->getId()}"]);
|
call_user_func_array($this->logError, [$th, "StatsResources", "count_for_project_{$project->getId()}"]);
|
||||||
} finally {
|
|
||||||
$this->documents = [];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Console::info('End of count for: ' . $project->getId());
|
Console::info('End of count for: ' . $project->getId());
|
||||||
|
|
@ -436,18 +434,32 @@ class StatsResources extends Action
|
||||||
{
|
{
|
||||||
$message = 'Stats writeDocuments project: ' . $project->getId() . '(' . $project->getSequence() . ')';
|
$message = 'Stats writeDocuments project: ' . $project->getId() . '(' . $project->getSequence() . ')';
|
||||||
|
|
||||||
|
// sort by unique index key to make
|
||||||
|
usort($this->documents, function($a, $b) {
|
||||||
|
// metric DESC
|
||||||
|
$cmp = strcmp($b['metric'], $a['metric']);
|
||||||
|
if ($cmp !== 0) return $cmp;
|
||||||
|
|
||||||
|
// period ASC
|
||||||
|
$cmp = strcmp($a['period'], $b['period']);
|
||||||
|
if ($cmp !== 0) return $cmp;
|
||||||
|
|
||||||
|
// time ASC
|
||||||
|
if ($a['time'] === $b['time']) return 0;
|
||||||
|
return ($a['time'] < $b['time']) ? -1 : 1;
|
||||||
|
});
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$dbForLogs->createOrUpdateDocuments(
|
$dbForLogs->createOrUpdateDocuments(
|
||||||
'stats',
|
'stats',
|
||||||
$this->documents
|
$this->documents,
|
||||||
|
10 // See if this make an effect
|
||||||
);
|
);
|
||||||
|
|
||||||
Console::success($message . ' | Documents: ' . count($this->documents));
|
Console::success($message . ' | Documents: ' . count($this->documents));
|
||||||
} catch (\Throwable $e) {
|
} catch (\Throwable $e) {
|
||||||
Console::error('Error: ' . $message . ' | Exception: ' . $e->getMessage());
|
Console::error('Error: ' . $message . ' | Exception: ' . $e->getMessage());
|
||||||
throw $e;
|
throw $e;
|
||||||
} finally {
|
|
||||||
$this->documents = [];
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue