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

Code before:
                            'deploymentVcsProviderBranch' => $branchName,
                            'status' => 'verified',
                            'certificateId' => '',
                            'search' => implode(' ', [$ruleId, $domain]),
                            'owner' => 'Appwrite',
                            'region' => $project->getAttribute('region')
                        ]));
                    } catch (Duplicate $err) {
                        $rule = $dbForPlatform->getDocument('rules', $ruleId);
                        $dbForPlatform->updateDocument('rules', $rule->getId(), new Document([
                            'deploymentId' => $deployment->getId(),
                            'deploymentInternalId' => $deployment->getSequence(),
                        ]));
                    }

                    $queries = [
                        Query::equal('projectInternalId', [$project->getSequence()]),
                        Query::equal('type', ['deployment']),
                        Query::equal('deploymentResourceInternalId', [$resource->getSequence()]),
                        Query::equal('deploymentResourceType', ['site']),
                        Query::equal('deploymentVcsProviderBranch', [$branchName]),
                        Query::equal('trigger', ['manual']),
                    ];

                    $dbForPlatform->foreach('rules', function (Document $rule) use ($dbForPlatform, $deployment) {
                        $dbForPlatform->updateDocument('rules', $rule->getId(), new Document([
                            'deploymentId' => $deployment->getId(),
                            'deploymentInternalId' => $deployment->getSequence(),
                        ]));
                    }, $queries);
                }
            }

            $endTime = DateTime::now();
            $durationEnd = \microtime(true);
            $deployment->setAttribute('buildEndedAt', $endTime);
            $deployment->setAttribute('buildDuration', \intval(\ceil($durationEnd - $durationStart)));
            $deployment = $dbForProject->updateDocument('deployments', $deployment->getId(), $deployment);
            $queueForRealtime
                ->setPayload($deployment->getArrayCopy())
                ->trigger();

            if ($dbForProject->getDocument('deployments', $deploymentId)->getAttribute('status') === 'canceled') {
                Console::info('Build has been canceled');
                return;
            }

            /** Update function schedule */

            // Inform scheduler if function is still active
            if ($resource->getCollection() === 'functions') {

Review comment (suggestion):
```suggestion
                        $rule = $dbForPlatform->updateDocument('rules', $rule->getId(), new Document([
```

Code after:
                            'deploymentResourceType' => 'site',
                            'deploymentResourceId' => $deployment->getId(),
                            'deploymentResourceInternalId' => $deployment->getSequence(),
                            'deploymentVcsProviderBranch' => $branchName,
                            'status' => 'verified',
                            'certificateId' => '',
                            'search' => implode(' ', [$ruleId, $domain]),
                            'owner' => 'Appwrite',
                            'region' => $project->getAttribute('region')
                        ]));
                    } catch (Duplicate $err) {
                        $rule = $dbForPlatform->updateDocument('rules', $ruleId, new Document([
                            'deploymentId' => $deployment->getId(),
                            'deploymentInternalId' => $deployment->getSequence(),
                        ]));
                    }

                    $queries = [
                        Query::equal('projectInternalId', [$project->getSequence()]),
                        Query::equal('type', ['deployment']),
                        Query::equal('deploymentResourceInternalId', [$resource->getSequence()]),
                        Query::equal('deploymentResourceType', ['site']),
                        Query::equal('deploymentVcsProviderBranch', [$branchName]),
                        Query::equal('trigger', ['manual']),
                    ];

                    $dbForPlatform->foreach('rules', function (Document $rule) use ($dbForPlatform, $deployment) {
                        $rule = $dbForPlatform->updateDocument('rules', $rule->getId(), new Document([
                            'deploymentId' => $deployment->getId(),
                            'deploymentInternalId' => $deployment->getSequence(),
                        ]));
                    }, $queries);
                }
            }

            $endTime = DateTime::now();
            $durationEnd = \microtime(true);
            $deployment->setAttribute('buildEndedAt', $endTime);
            $deployment->setAttribute('buildDuration', \intval(\ceil($durationEnd - $durationStart)));
            $deployment = $dbForProject->updateDocument('deployments', $deployment->getId(), $deployment);
            $queueForRealtime
                ->setPayload($deployment->getArrayCopy())
                ->trigger();

            if ($dbForProject->getDocument('deployments', $deploymentId)->getAttribute('status') === 'canceled') {
                Console::info('Build has been canceled');
                return;
            }

            /** Update function schedule */