Skip to content

Commit b6766b5

Browse files
committed
perf: also do updater optimization for deleting for object store
Signed-off-by: Robin Appelman <robin@icewind.nl>
1 parent 82f43ba commit b6766b5

File tree

2 files changed

+30
-4
lines changed

2 files changed

+30
-4
lines changed

lib/private/Files/ObjectStore/ObjectStoreStorage.php

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,23 @@ public function rmdir(string $path): bool {
153153
return false;
154154
}
155155

156-
return $this->rmObjects($entry);
156+
$result = $this->rmObjects($entry);
157+
if ($result) {
158+
$this->removeFromCache($entry);
159+
}
160+
return $result;
161+
}
162+
163+
/**
164+
* Remove an item from cache and propagate the change to the parent folders.
165+
*
166+
* Similar logic to the `Updater` but done in-storage because we have the correct info to avoid expensive
167+
* folder size calculations.
168+
*/
169+
private function removeFromCache(ICacheEntry $entry): void {
170+
$this->cache->remove($entry->getId());
171+
$this->getUpdater()->correctParentStorageMtime($entry->getPath());
172+
$this->propagator->propagateChange($entry->getPath(), time(), -$entry->getSize());
157173
}
158174

159175
private function rmObjects(ICacheEntry $entry): bool {
@@ -180,15 +196,21 @@ private function rmObjects(ICacheEntry $entry): bool {
180196
public function unlink(string $path): bool {
181197
$path = $this->normalizePath($path);
182198
$entry = $this->getCache()->get($path);
199+
$result = false;
183200

184201
if ($entry instanceof ICacheEntry) {
185202
if ($entry->getMimeType() === ICacheEntry::DIRECTORY_MIMETYPE) {
186-
return $this->rmObjects($entry);
203+
$result = $this->rmObjects($entry);
187204
} else {
188-
return $this->rmObject($entry);
205+
$result = $this->rmObject($entry);
189206
}
190207
}
191-
return false;
208+
209+
if ($result) {
210+
$this->removeFromCache($entry);
211+
}
212+
213+
return $result;
192214
}
193215

194216
public function rmObject(ICacheEntry $entry): bool {

lib/private/Files/ObjectStore/ObjectStoreUpdater.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,8 @@ class ObjectStoreUpdater extends Updater {
1818
public function update($path, $time = null, ?int $sizeDifference = null) {
1919
// Noop
2020
}
21+
22+
public function remove($path) {
23+
// Noop
24+
}
2125
}

0 commit comments

Comments
 (0)