Repository: appwrite/appwrite
File: src/Appwrite/Platform/Modules/Functions/Workers/Builds.php (PHP)

Code before:
                $message = "[31m" . $message;
            }

            $message = \str_replace('{APPWRITE_DETECTION_SEPARATOR_START}', '', $message);
            $message = \str_replace('{APPWRITE_DETECTION_SEPARATOR_END}', '', $message);

            // Combine with previous logs if deployment got past build process
            $previousLogs = '';
            if (!is_null($deployment->getAttribute('buildSize', null))) {
                $previousLogs = $deployment->getAttribute('buildLogs', '');
                if (!empty($previousLogs)) {
                    $message = $previousLogs . "\n" . $message;
                }
            }

            $endTime = DateTime::now();
            $durationEnd = \microtime(true);
            $deployment->setAttribute('buildEndedAt', $endTime);
            $deployment->setAttribute('buildDuration', \intval(\ceil($durationEnd - $durationStart)));
            $deployment->setAttribute('status', 'failed');

            $deployment->setAttribute('buildLogs', $message);
            $deployment = $dbForProject->updateDocument('deployments', $deploymentId, $deployment);

            if ($deployment->getSequence() === $resource->getAttribute('latestDeploymentInternalId', '')) {
                $dbForProject->updateDocument($resource->getCollection(), $resource->getId(), new Document(['latestDeploymentStatus' => $deployment->getAttribute('status', '')]));
            }

            $queueForRealtime
                ->setPayload($deployment->getArrayCopy())
                ->trigger();

            if ($isVcsEnabled) {
                $this->runGitAction('failed', $github, $providerCommitHash, $owner, $repositoryName, $project, $resource, $deployment->getId(), $dbForProject, $dbForPlatform);
            }
        } finally {
            $queueForRealtime
                ->setPayload($deployment->getArrayCopy())
                ->trigger();

            $this->sendUsage(
                resource:$resource,
                deployment: $deployment,
                project: $project,
                queue: $queueForStatsUsage
            );
        }
    }

    protected function sendUsage(Document $resource, Document $deployment, Document $project, StatsUsage $queue): void
    {

Review comment (suggestion):
```suggestion
                $resource = $dbForProject->updateDocument($resource->getCollection(), $resource->getId(), new Document(['latestDeploymentStatus' => $deployment->getAttribute('status', '')]));
```

Code after:
            $message = $th->getMessage();
            if (!\str_contains($message, '')) {
                $message = "[31m" . $message;
            }

            $message = \str_replace('{APPWRITE_DETECTION_SEPARATOR_START}', '', $message);
            $message = \str_replace('{APPWRITE_DETECTION_SEPARATOR_END}', '', $message);

            // Combine with previous logs if deployment got past build process
            $previousLogs = '';
            if (!is_null($deployment->getAttribute('buildSize', null))) {
                $previousLogs = $deployment->getAttribute('buildLogs', '');
                if (!empty($previousLogs)) {
                    $message = $previousLogs . "\n" . $message;
                }
            }

            $endTime = DateTime::now();
            $durationEnd = \microtime(true);
            $deployment->setAttribute('buildEndedAt', $endTime);
            $deployment->setAttribute('buildDuration', \intval(\ceil($durationEnd - $durationStart)));
            $deployment->setAttribute('status', 'failed');

            $deployment->setAttribute('buildLogs', $message);
            $deployment = $dbForProject->updateDocument('deployments', $deploymentId, $deployment);

            if ($deployment->getSequence() === $resource->getAttribute('latestDeploymentInternalId', '')) {
                $resource = $dbForProject->updateDocument($resource->getCollection(), $resource->getId(), new Document(['latestDeploymentStatus' => $deployment->getAttribute('status', '')]));
            }

            $queueForRealtime
                ->setPayload($deployment->getArrayCopy())
                ->trigger();

            if ($isVcsEnabled) {
                $this->runGitAction('failed', $github, $providerCommitHash, $owner, $repositoryName, $project, $resource, $deployment->getId(), $dbForProject, $dbForPlatform);
            }
        } finally {
            $queueForRealtime
                ->setPayload($deployment->getArrayCopy())
                ->trigger();

            $this->sendUsage(
                resource:$resource,
                deployment: $deployment,
                project: $project,
                queue: $queueForStatsUsage
            );
        }
    }