Skip to content

Commit 01b0c6a

Browse files
abnegateclaude
andcommitted
perf(database): inline events-silence toggle in find collection lookup
The opening line of find() wrapped getCollection in silent(fn () => ...) solely to suppress the CollectionRead event. The closure allocation showed up alongside Authorization::skip in the profile, both for the same reason: a tiny flag toggle hidden behind a callable. Set/restore eventsSilenced directly. With both inlines together, order_cursor drops another ~15% wall time. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent 13e4edb commit 01b0c6a

1 file changed

Lines changed: 9 additions & 1 deletion

File tree

src/Database/Traits/Documents.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2125,7 +2125,15 @@ public function purgeCachedDocument(string $collectionId, ?string $id): bool
21252125
*/
21262126
public function find(string $collection, array $queries = [], PermissionType $forPermission = PermissionType::Read): array
21272127
{
2128-
$collection = $this->silent(fn () => $this->getCollection($collection));
2128+
// Inline silent() to avoid the per-find closure allocation; only the
2129+
// CollectionRead event needs to be suppressed for this lookup.
2130+
$previousSilenced = $this->eventsSilenced;
2131+
$this->eventsSilenced = true;
2132+
try {
2133+
$collection = $this->getCollection($collection);
2134+
} finally {
2135+
$this->eventsSilenced = $previousSilenced;
2136+
}
21292137

21302138
if ($collection->isEmpty()) {
21312139
throw new NotFoundException('Collection not found');

0 commit comments

Comments
 (0)