-
-
Notifications
You must be signed in to change notification settings - Fork 401
Purge database connection only when migrating or seeding multiple tenants #656
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
Conversation
|
Thank you for your time in writing this PR. I will try to have time to check on this. But all seems to be green and ready to go. Just need to double check. 👍 Cheers! |
| $this->input->setOption('database', $this->connection->tenantName()); | ||
|
|
||
| $this->processHandle(function ($website) { | ||
| $this->processHandle(function (Website $website, Collection $websites) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of passing the full collection (thus creating a full copy in memory), why don't we make it a boolean?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@fletch3555 I think making it a boolean would make processHandle method too much concentrated to this issue. Maybe passing chunkSize integer would be a better idea? What do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I mean, its already specific to this issue, right? All it's checking is if the count > 1 then purging. Would make sense to simply pass in $shouldPurge as a boolean and leave the decision on why elsewhere
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I mean processHandle method is not responsible for managing the connection and it should know nothing about it, so adding connection specific logic seems not right to me. All it does is running the provided callback on the chunks of tenants. So passing the information about the chunk seems more clean to me:
$this->processHandle(function (Website $website, $chunkSize) {
$this->connection->set($website);
parent::handle();
if ($chunkSize > 1) {
$this->connection->purge();
}
});There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fletch is right though. You're sending an argument into a method that will possibly increase the memory footprint. Either we move the purge out of the processHandle or we use a boolean argument (bool $purge = true).
What do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@luceos I agree with Fletch on memory footprint issue, but I don't agree with his proposed solution. Moving connection handling out of closure seems like a better way to solve this. I've just updated the code. What do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey @luceos and @fletch3555, are there still any problems with this PR?
luceos
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is okay as is, but please fix the use of $websiteB in the tests, there's no reason to use a variable like that in the scope of the test functions, $website will suffice.
Thanks for your patience, I love your parent::handle() fallback, great idea! 👏
|
🎆 thank you! Time to tag a new version soon 👍 |
Current implementation of
tenancy:migrateandtenancy:seedcommands purges the database connection no matter of how many tenants are migrated or seeded. It means that it can’t be used with SQLite in-memory databases and that makes testing more complex.This PR updates
tenancy:migrateandtenancy:seedcommands to only purge the database connection when multiple tenants are migrated or seeded, which makesTenantAwareTestCasemore simple and elegant compared to the older version (#627 (comment)):