Skip to content

Commit bc05d0d

Browse files
committed
cache
1 parent 9c7e18d commit bc05d0d

4 files changed

Lines changed: 51 additions & 37 deletions

File tree

composer.lock

Lines changed: 19 additions & 19 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Database/Adapter/SQL.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1549,6 +1549,8 @@ protected function getAttributeProjection(array $selections, string $prefix = ''
15491549
return '*';
15501550
}
15511551

1552+
$selections = \array_diff($selections, ['$id', '$permissions', '$collection']);
1553+
15521554
$selections[] = $this->getInternalKeyForAttribute('$id');
15531555
$selections[] = $this->getInternalKeyForAttribute('$permissions');
15541556

src/Database/Database.php

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6440,25 +6440,21 @@ public function getSchemaAttributes(string $collection): array
64406440
*/
64416441
public function getCacheKeys(string $collectionId, ?string $documentId = null, array $selects = []): array
64426442
{
6443+
$hostname = '';
6444+
64436445
if ($this->getSharedTables()) {
6444-
$collectionKey = \sprintf(
6445-
'%s-cache-%s:%s:%s:collection:%s',
6446-
$this->cacheName,
6447-
$this->adapter->getHostname(),
6448-
$this->getNamespace(),
6449-
$this->adapter->getTenant(),
6450-
$collectionId
6451-
);
6452-
} else {
6453-
$collectionKey = \sprintf(
6454-
'%s-cache-%s:%s:collection:%s',
6455-
$this->cacheName,
6456-
$this->getNamespace(),
6457-
$this->adapter->getTenant(),
6458-
$collectionId
6459-
);
6446+
$hostname = $this->adapter->getHostname();
64606447
}
64616448

6449+
$collectionKey = \sprintf(
6450+
'%s-cache-%s:%s:%s:collection:%s',
6451+
$this->cacheName,
6452+
$hostname,
6453+
$this->getNamespace(),
6454+
$this->adapter->getTenant(),
6455+
$collectionId
6456+
);
6457+
64626458
if ($documentId) {
64636459
$documentKey = $documentHashKey = "{$collectionKey}:{$documentId}";
64646460

src/Database/PDO.php

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,15 +59,31 @@ public function reconnect(): void
5959

6060
public function getScheme(): string
6161
{
62-
$parts = parse_url($this->dsn);
62+
$parts = $this->parseDsn($this->dsn);
6363

6464
return $parts['scheme'] ?? throw new \Exception('No scheme found in DSN');
6565
}
6666

6767
public function getHostname(): string
6868
{
69-
$parts = parse_url($this->dsn);
69+
$parts = $this->parseDsn($this->dsn);
7070

7171
return $parts['host'] ?? throw new \Exception('No host found in DSN');
7272
}
73+
public function parseDsn(string $dsn):array
74+
{
75+
$result = [];
76+
77+
[$driver, $params] = explode(':', $dsn, 2);
78+
$result['driver'] = $driver;
79+
80+
foreach (explode(';', $params) as $pair) {
81+
if (str_contains($pair, '=')) {
82+
[$key, $value] = explode('=', $pair, 2);
83+
$result[$key] = $value;
84+
}
85+
}
86+
87+
return $result;
88+
}
7389
}

0 commit comments

Comments
 (0)