Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 39 additions & 1 deletion src/Database/Database.php
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,13 @@ class Database

protected bool $migrating = false;

/**
* List of collections that should be treated as globally accessible
*
* @var array<string, bool>
*/
protected array $globalCollections = [];

/**
* Stack of collection IDs when creating or updating related documents
* @var array<string>
Expand Down Expand Up @@ -1013,6 +1020,31 @@ public function getMaxQueryValues(): int
return $this->maxQueryValues;
}

/**
* Set list of collections which are globally accessible
*
* @param array<string> $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<string>
*/
public function getGlobalCollections(): array
{
return \array_keys($this->globalCollections);
}

/**
* Get list of keywords that cannot be used
*
Expand Down Expand Up @@ -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
);

Expand Down