Skip to content

Commit f9c2b6b

Browse files
authored
Merge pull request #569 from utopia-php/feat-global-collections
Allow setting global collections
2 parents 7403547 + d8ada3d commit f9c2b6b

File tree

1 file changed

+39
-1
lines changed

1 file changed

+39
-1
lines changed

src/Database/Database.php

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -349,6 +349,13 @@ class Database
349349

350350
protected bool $migrating = false;
351351

352+
/**
353+
* List of collections that should be treated as globally accessible
354+
*
355+
* @var array<string, bool>
356+
*/
357+
protected array $globalCollections = [];
358+
352359
/**
353360
* Stack of collection IDs when creating or updating related documents
354361
* @var array<string>
@@ -1013,6 +1020,31 @@ public function getMaxQueryValues(): int
10131020
return $this->maxQueryValues;
10141021
}
10151022

1023+
/**
1024+
* Set list of collections which are globally accessible
1025+
*
1026+
* @param array<string> $collections
1027+
* @return $this
1028+
*/
1029+
public function setGlobalCollections(array $collections): static
1030+
{
1031+
foreach ($collections as $collection) {
1032+
$this->globalCollections[$collection] = true;
1033+
}
1034+
1035+
return $this;
1036+
}
1037+
1038+
/**
1039+
* Get list of collections which are globally accessible
1040+
*
1041+
* @return array<string>
1042+
*/
1043+
public function getGlobalCollections(): array
1044+
{
1045+
return \array_keys($this->globalCollections);
1046+
}
1047+
10161048
/**
10171049
* Get list of keywords that cannot be used
10181050
*
@@ -6472,12 +6504,18 @@ public function getCacheKeys(string $collectionId, ?string $documentId = null, a
64726504
$hostname = $this->adapter->getHostname();
64736505
}
64746506

6507+
$tenantSegment = $this->adapter->getTenant();
6508+
6509+
if (isset($this->globalCollections[$collectionId])) {
6510+
$tenantSegment = null;
6511+
}
6512+
64756513
$collectionKey = \sprintf(
64766514
'%s-cache-%s:%s:%s:collection:%s',
64776515
$this->cacheName,
64786516
$hostname ?? '',
64796517
$this->getNamespace(),
6480-
$this->adapter->getTenant(),
6518+
$tenantSegment,
64816519
$collectionId
64826520
);
64836521

0 commit comments

Comments
 (0)