Skip to content

PropPatch handler should be called only once for bulk updates #1349

Description

@hschletz

PropPatch::handleRemaining() registers a callback for every single property. However, the callback receives the full list of properties which all get handled in the first iteration, making every subsequent iteration redundant. At best, this does nothing except having a potential perfomance impact. At worst, the callback has side effects which may cause unexpected behaviour.

As a workaround, I keep track of the operation and abort the redundant callback invocations:

class PropertiesBackend implements BackendInterface
{
    private bool $updateInProgress = false;

    public function propPatch($path, PropPatch $propPatch): void
    {
        $propPatch->handleRemaining(fn($changedProps) => $this->updateProperties($changedProps));
        $this->updateInProgress = false;
    }

    private function updateProperties(array $properties): bool
    {
        if ($this->updateInProgress) {
            return true;
        }
        $this->updateInProgress = true;
        ...
    }
    ...
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions