[10.x] Laravel 10x optional withSize for hasTable #50888
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
In an effort to enhance the performance of SQLite tests and streamline the functionality of the SQLiteBuilder's getTables method, this pull request introduces an optimisation by making the withSize parameter optional. This change allows for a reduction in unnecessary queries, particularly for trivial actions where table size information is not needed.
Background:
Previously, the determination of whether to include table size in the results (withSize) was attempted through a direct query using
compileDbstatExists().
This approach was fixed and did not account for cases where fetching table size was not required, leading to unnecessary execution of database queries.Implementation Changes:
The new implementation introduces an optional parameter $withSize to the getTables method. This parameter allows callers to explicitly state whether table size information should be included (true), not included (false), or decided based on the existence of the DBSTAT virtual table (null). This is achieved through a match expression that either directly uses the $forceWithSize value if it's boolean or dynamically determines the value by attempting to query the database for the DBSTAT virtual table's existence. This approach significantly reduces unnecessary database interactions, especially in scenarios where table size information is irrelevant.
Benchmarks
I setup a simple benchmark check in
DatabaseMigratorIntegrationTest
just to get proof:Benefits to End Users:
Improved Performance: By avoiding unnecessary queries, the overall performance of interacting with SQLite databases, especially in testing environments, is improved.
Flexibility: Users now have the option to explicitly decide whether or not table size information is needed, allowing for more tailored and efficient database interactions.
Simplicity and Backward Compatibility: The change is implemented in a backward-compatible manner, ensuring that existing applications will not be affected. The simplicity of opting in or out of fetching table size information makes this enhancement seamlessly integrate into existing workflows.
Ensuring Non-breaking Change:
This update does not alter the default behaviour of the getTables method unless explicitly instructed by the user, ensuring no unexpected changes for existing users.
Comprehensive testing has been conducted to ensure that this change does not introduce any regressions or break any existing features.
Conclusion:
Making the withSize parameter optional in the SQLiteBuilder's getTables method is a significant optimisation that reduces unnecessary database queries, thereby speeding up SQLite tests and making web application development easier and more efficient. This change demonstrates a commitment to improving the developer experience without compromising the integrity of existing applications.
Existing test coverage should be sufficient to confirm that the existing behaviour is unchanged.