dav icon indicating copy to clipboard operation
dav copied to clipboard

PropPatch handler should be called only once for bulk updates

Open hschletz opened this issue 3 years ago • 1 comments

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;
        ...
    }
    ...
}

hschletz avatar Aug 23 '21 08:08 hschletz

Feel free to submit a pull request this these changes including a test case. THX a lot

DeepDiver1975 avatar Aug 27 '21 10:08 DeepDiver1975