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

Code before:
                    $domain = "branch-{$branchPrefix}-{$resourceProjectHash}.{$sitesDomain}";
                    $ruleId = md5($domain);

                    try {
                        $dbForPlatform->createDocument('rules', new Document([
                            '$id' => $ruleId,
                            'projectId' => $project->getId(),
                            'projectInternalId' => $project->getSequence(),
                            'domain' => $domain,
                            'type' => 'deployment',
                            'trigger' => 'deployment',
                            'deploymentId' => $deployment->getId(),
                            'deploymentInternalId' => $deployment->getSequence(),
                            '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->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);

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

Code after:
                        $branchPrefix .= '-' . substr(hash('sha256', $remainingChars), 0, 7);
                    }
                    $resourceProjectHash = substr(hash('sha256', $resource->getId() . $project->getId()), 0, 7);
                    $domain = "branch-{$branchPrefix}-{$resourceProjectHash}.{$sitesDomain}";
                    $ruleId = md5($domain);

                    try {
                        $dbForPlatform->createDocument('rules', new Document([
                            '$id' => $ruleId,
                            'projectId' => $project->getId(),
                            'projectInternalId' => $project->getSequence(),
                            'domain' => $domain,
                            'type' => 'deployment',
                            'trigger' => 'deployment',
                            'deploymentId' => $deployment->getId(),
                            'deploymentInternalId' => $deployment->getSequence(),
                            '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);
                }
            }