CHG: Optimize scopeCurrentStatus
and scopeOtherCurrentStatus
Query
#124
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.
Overview
This PR proposes an optimization for the
scopeCurrentStatus
method in thelaravel-model-status
package. The current implementation uses a nested query withMAX(id)
which can lead to performance issues on large datasets.Changes
scopeCurrentStatus
method to remove the nestedMAX(id)
query.id
, assuming the latest status has the highestid
.Impact
Tests
I believe this optimization will be beneficial for users experiencing performance issues with the current implementation of
scopeCurrentStatus
. Looking forward to your feedback and suggestions.Proposed Test for Performance Evaluation
While making the optimizations to the
scopeCurrentStatus
method, I also devised a performance test to evaluate the improvements. It's important to note that the performance gains may vary depending on the specific server environment and database size. In my local testing environment, the performance difference was not significant, but it showed more noticeable improvements on a production-like server setup.Here's the example test:
Important Note
This test is provided as an example to demonstrate how one might measure the performance improvements. The actual performance gains can be more significant on systems with larger datasets and in different server configurations. I recommend running this test in your specific environment to gauge the performance improvements.