mirror of
https://github.com/archtechx/tenancy.git
synced 2026-02-05 07:54:03 +00:00
Separate data & domains logic
This commit is contained in:
parent
a86412af09
commit
0deb1f1376
2 changed files with 10 additions and 6 deletions
|
|
@ -34,12 +34,14 @@ class CachedTenantResolver
|
|||
return $this->cache->remember('_tenancy_domain_to_id:' . $domain, $this->ttl(), $query);
|
||||
}
|
||||
|
||||
public function findById(string $id, Closure $dataQuery, Closure $domainsQuery): Tenant
|
||||
public function getDataById(string $id, Closure $dataQuery): ?array
|
||||
{
|
||||
$data = $this->cache->remember('_tenancy_id_to_data:' . $id, $this->ttl(), $dataQuery);
|
||||
$domains = $this->cache->remember('_tenancy_id_to_domains:' . $id, $this->ttl(), $domainsQuery);
|
||||
return $this->cache->remember('_tenancy_id_to_data:' . $id, $this->ttl(), $dataQuery);
|
||||
}
|
||||
|
||||
return Tenant::fromStorage($data)->withDomains($domains);
|
||||
public function getDomainsById(string $id, Closure $domainsQuery): ?array
|
||||
{
|
||||
return $this->cache->remember('_tenancy_id_to_domains:' . $id, $this->ttl(), $domainsQuery);
|
||||
}
|
||||
|
||||
public function invalidateTenant(string $id): void
|
||||
|
|
|
|||
|
|
@ -91,9 +91,11 @@ class DatabaseStorageDriver implements StorageDriver, CanDeleteKeys, CanFindByAn
|
|||
};
|
||||
|
||||
if ($this->usesCache()) {
|
||||
return $this->cache->findById($id, $dataQuery, $domainsQuery);
|
||||
$data = $this->cache->getDataById($id, $dataQuery);
|
||||
$domains = $this->cache->getDomainsById($id, $domainsQuery);
|
||||
} else {
|
||||
$data = $dataQuery();
|
||||
$domains = $domainsQuery();
|
||||
}
|
||||
|
||||
if (! $data) {
|
||||
|
|
@ -101,7 +103,7 @@ class DatabaseStorageDriver implements StorageDriver, CanDeleteKeys, CanFindByAn
|
|||
}
|
||||
|
||||
return Tenant::fromStorage($data)
|
||||
->withDomains($domainsQuery());
|
||||
->withDomains($domains);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue