diff --git a/src/Database/Database.php b/src/Database/Database.php index c50354a1f..3ef2dab4a 100644 --- a/src/Database/Database.php +++ b/src/Database/Database.php @@ -349,6 +349,13 @@ class Database protected bool $migrating = false; + /** + * List of collections that should be treated as globally accessible + * + * @var array + */ + protected array $globalCollections = []; + /** * Stack of collection IDs when creating or updating related documents * @var array @@ -1013,6 +1020,31 @@ public function getMaxQueryValues(): int return $this->maxQueryValues; } + /** + * Set list of collections which are globally accessible + * + * @param array $collections + * @return $this + */ + public function setGlobalCollections(array $collections): static + { + foreach ($collections as $collection) { + $this->globalCollections[$collection] = true; + } + + return $this; + } + + /** + * Get list of collections which are globally accessible + * + * @return array + */ + public function getGlobalCollections(): array + { + return \array_keys($this->globalCollections); + } + /** * Get list of keywords that cannot be used * @@ -6472,12 +6504,18 @@ public function getCacheKeys(string $collectionId, ?string $documentId = null, a $hostname = $this->adapter->getHostname(); } + $tenantSegment = $this->adapter->getTenant(); + + if (isset($this->globalCollections[$collectionId])) { + $tenantSegment = null; + } + $collectionKey = \sprintf( '%s-cache-%s:%s:%s:collection:%s', $this->cacheName, $hostname ?? '', $this->getNamespace(), - $this->adapter->getTenant(), + $tenantSegment, $collectionId );