limit sql length to avoid breaking the json #326
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.
Issue
We've identified a bug within Laravel Pulse where if the slow query detector captures an excessively large SQL statement, it leads to a disruption in the JSON schema stored in the database. This disruption makes it impossible to read the affected data, impacting the tool's ability to provide accurate insights into application performance.
Root Cause
The root cause of this issue lies in the default length of the database column designated for storing SQL statements. When a captured SQL statement exceeds this default length (65535), the resulting JSON encoding process creates a payload that violates the column's size constraints, leading to corruption of the JSON schema and subsequent data retrieval problems.
Proposed Solution
To address this issue, I propose implementing a check to truncate SQL statements to a maximum character length before encoding them into JSON. This approach ensures that the payload size remains within the database field size constraints, thus preserving the integrity of the JSON schema.
Changes Made
Start using
Str::limit($sql, 65000)
to make sure we are not getting too close to the limit.Impact
This fix ensures that Laravel Pulse can handle large SQL statements without compromising the JSON schema's integrity in the database, thereby maintaining the tool's efficacy in providing performance insights.