mirror of
https://github.com/appwrite/appwrite.git
synced 2026-11-18 20:36:03 +00:00
Merge remote-tracking branch 'origin/1.8.x' into feat-txn
# Conflicts: # composer.lock # src/Appwrite/Platform/Workers/StatsResources.php # src/Appwrite/Platform/Workers/StatsUsage.php
This commit is contained in:
15 files changed
+700
-83
No files matched your search
@@ -424,12 +424,41 @@ class StatsUsage extends Action
|
||||
try {
|
||||
$dbForProject = $getProjectDB($projectStats['project']);
|
||||
Console::log('Processing batch with ' . count($projectStats['stats']) . ' stats');
|
||||
$dbForProject->upsertDocumentsWithIncrease('stats', 'value', $projectStats['stats']);
|
||||
Console::success('Batch successfully written to DB');
|
||||
|
||||
/**
|
||||
* Sort by unique index key reduce locks/deadlocks
|
||||
*/
|
||||
usort($projectStats['stats'], function ($a, $b) {
|
||||
// Metric DESC
|
||||
$cmp = strcmp($b['metric'], $a['metric']);
|
||||
if ($cmp !== 0) {
|
||||
return $cmp;
|
||||
}
|
||||
|
||||
unset($this->projects[$sequence]);
|
||||
// Period ASC
|
||||
$cmp = strcmp($a['period'], $b['period']);
|
||||
if ($cmp !== 0) {
|
||||
return $cmp;
|
||||
}
|
||||
|
||||
// Time ASC, NULLs first
|
||||
if ($a['time'] === null) {
|
||||
return ($b['time'] === null) ? 0 : -1;
|
||||
}
|
||||
if ($b['time'] === null) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
return strcmp($a['time'], $b['time']);
|
||||
});
|
||||
|
||||
$dbForProject->upsertDocumentsWithIncrease('stats', 'value', $projectStats['stats']);
|
||||
Console::success('Batch successfully written to DB');
|
||||
} catch (Throwable $e) {
|
||||
Console::error('Error processing stats: ' . $e->getMessage());
|
||||
} finally {
|
||||
unset($this->projects[$sequence]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -468,12 +497,53 @@ class StatsUsage extends Action
|
||||
|
||||
try {
|
||||
Console::log('Processing batch with ' . count($this->statDocuments) . ' stats');
|
||||
$dbForLogs->upsertDocumentsWithIncrease(
|
||||
|
||||
/**
|
||||
* Sort by UNIQUE KEY "_key_metric_period_time" ("_tenant","metric" DESC,"period","time")
|
||||
* Here we sort by _tenant as well because of setTenantPerDocument
|
||||
*/
|
||||
|
||||
usort($this->statDocuments, function ($a, $b) {
|
||||
// Tenant ASC
|
||||
$cmp = $a['$tenant'] <=> $b['$tenant'];
|
||||
if ($cmp !== 0) {
|
||||
return $cmp;
|
||||
}
|
||||
|
||||
// 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, NULLs first
|
||||
if ($a['time'] === null) {
|
||||
return ($b['time'] === null) ? 0 : -1;
|
||||
}
|
||||
if ($b['time'] === null) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
return strcmp($a['time'], $b['time']);
|
||||
});
|
||||
|
||||
$dbForLogs->createOrUpdateDocumentsWithIncrease(
|
||||
'stats',
|
||||
'value',
|
||||
$this->statDocuments
|
||||
);
|
||||
Console::success('Usage logs pushed to Logs DB');
|
||||
|
||||
/**
|
||||
* todo: Do we need to unset $this->statDocuments?
|
||||
*/
|
||||
|
||||
} catch (Throwable $th) {
|
||||
Console::error($th->getMessage());
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user