-
-
Notifications
You must be signed in to change notification settings - Fork 437
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix issue 632: cached lookup #633
Conversation
…ain 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.
…older PHP versions, replaced with inline if
I can't reproduce these failures locally with running tests on docker, with PHP 8.0 and trying both Laravel ^6.0 and ^8.0. |
… current domain is found and relationship is loaded (with only one domain).
…iedFromCache() method and removed duplicate code, when setting current domain.
Codecov Report
@@ Coverage Diff @@
## 3.x #633 +/- ##
============================================
+ Coverage 86.92% 86.98% +0.06%
- Complexity 366 369 +3
============================================
Files 103 103
Lines 1086 1099 +13
============================================
+ Hits 944 956 +12
- Misses 142 143 +1
Continue to review full report at Codecov.
|
Now, with this pull request:
|
…omain(), refactored the usage of tenantIdentified().
I made some changes to the code, can you please check what test started failing? |
@stancl Github Actions sometimes fail for no reason. Thanks for the cleanup! I pushed a commit (to get the tests run again) and now everything passed. |
Thanks! |
I'm getting below error after upgrade from 3.4.2 to 3.4.3
|
Same to me, I getting error like that after upgrade from 3.4.2 to 3.4.3 |
@shimsag could you please open an issue with details and steps to reproduce. I think the problem is in your code. Can't assist without details. |
In my case, I'm using Postgres 11, and everything is normal, but after i run composer update, when I try to open tenant domain, I'm getting those error.
|
What's your data type for |
The only change is that the domain is not getting fetched via |
Data type for tenant_id column on domains table is varchar(255), for example "cbab4d88-5b45-4c91-8cf7-37accf642960", this is same data type with id column on tenants table, i'm using saas boilerplate and using postgresql database, and this problem occured after composer update. |
Can you try running |
Nice, it works now, thank you @stancl for the fast response. |
Great, thanks! |
Fixes #632
What I changed
https://github.com/stancl/tenancy/blob/27e9fb4a692a15ca2fd320799d97fc657cb14b68/src/Resolvers/DomainTenantResolver.php#L31-L38
Instead of querying Domain model, find Tenant and eager load its domains via Tenant model. This way, you get
$tenant
, which already has loadeddomains
relationship, with only the current domain (Tenant can have many domains, but. This reduces SQL queries and memory usage - when using cache, Domain models are loaded from cache, not from the central database. Now there is no need to access central database, if you need to get current Domain or Tenant models, or any of Tenant's domains.$tenant->domains
will have only the identified domain!)Added a new method toCachedTenantResolver
-tenantIdentifiedFromCache(Tenant $tenant, ...$args)
, which is called everytime, when Tenant is identified from cache. Then it's used in resolver, to set the current domain.Added a new method to
CachedTenantResolver
-tenantIdentified(Tenant $tenant, ...$args)
, which is used to set$currentDomain
inDomainTenantResolver
.