1
0
Fork 0
mirror of https://github.com/archtechx/tenancy.git synced 2025-12-12 12:54:05 +00:00

Fix issue 632: cached lookup (#633)

* Instead of querying Domain model, find Tenant and eager load it's domain via Tenant model. Fixed cached lookup issue - when caching Tenant, also include the current Domain, so it can be later accessed via $tenant->domains->first() (even, when using multiple domains per tenant). Added tenantIdentifiedFromCache method in CachedTenantResolver.php, which can be used to set custom properties in resolvers after Tenant is loaded from cache.

* StlyeCi Fix - removed PHP 8 nullsafe operator for compatibility with older PHP versions, replaced with inline if

* Redundant variable '$domain', because $tenant is not null, only, when current domain is found and relationship is loaded (with only one domain).

* Fixed tenant()->domains showing incorrect data. Renamed tenantIdentifiedFromCache() method and removed duplicate code, when setting current domain.

* Removed select() for better flexibility, added new method setCurrentDomain(), refactored the usage of tenantIdentified().

* rename method to resolved()

* clean up code

* StyleCi Fix

Co-authored-by: Samuel Štancl <samuel.stancl@gmail.com>
This commit is contained in:
Ralfs 2021-04-16 20:57:41 +03:00 committed by GitHub
parent 27e9fb4a69
commit c21beabd3e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 32 additions and 6 deletions

View file

@ -37,7 +37,11 @@ abstract class CachedTenantResolver implements TenantResolver
$key = $this->getCacheKey(...$args);
if ($this->cache->has($key)) {
return $this->cache->get($key);
$tenant = $this->cache->get($key);
$this->resolved($tenant, ...$args);
return $tenant;
}
$tenant = $this->resolveWithoutCache(...$args);
@ -64,6 +68,10 @@ abstract class CachedTenantResolver implements TenantResolver
abstract public function resolveWithoutCache(...$args): Tenant;
public function resolved(Tenant $tenant, ...$args): void
{
}
/**
* Get all the arg combinations for resolve() that can be used to find this tenant.
*