rails changelog


Changelog

Welcome to the latest updates! We've been busy squashing bugs and making some nifty improvements. Here's what's new:


New feature: Always discard Trilogy multi-statement results

  • Improved handling of multi-statement results in the Trilogy adapter for ActiveRecord.
  • Ensured results are discarded on the same connection used for the query, eliminating unnecessary connection management and enhancing performance. 🚀

New feature: Always discard mysql2 multi-statement results

  • Enhanced the MySQL2 adapter to discard multi-statement results consistently.
  • Incorporated abandon_results! logic within the raw_execute method for better resource management.

New feature: Optimize ActiveRecord::QueryLogs

  • Optimized ActiveRecord::QueryLogs to significantly reduce memory allocation and improve performance.
  • Benchmarked improvements show memory usage dropping from 1440 bytes to 840 bytes and speed increasing from 521.552k to 1.070M iterations per second. 🏎️💨

Bugfix: Fix test command to exit 1 on LoadError

  • Ensured the test command exits with status code 1 on a LoadError.
  • Modified DidYouMean search to trigger only when the specific test file fails to load, improving error handling.

Bugfix: Address ApplicationTests::QueryLogsTest errors

  • Resolved NoMethodError in ApplicationTests::QueryLogsTest related to the update_formatter method.
  • Ensured the test runs successfully, improving test suite stability.

Bugfix: Fix specs for QueryLogsTest#test_sql_commenter_format

  • Addressed issues in QueryLogsTest related to SQL commenter format.
  • Ensured test specifications align with intended functionality, enhancing reliability.

Included Commits

2024-07-22T13:20:42 See commit

The commit focuses on optimizing the ActiveRecord::QueryLogs component, which was identified as a significant contributor to memory allocation in production environments. The author aimed to enhance performance while maintaining the existing interface, although much of the functionality is private and intended for configuration through the application.config. The benchmarks demonstrate a notable reduction in memory allocation, dropping from 1440 bytes with 18 objects to just 840 bytes with 7 objects, while also improving the speed of tag calculations from approximately 521.552k iterations per second to 1.070M iterations per second.

In addition to the performance improvements, the commit includes a benchmarking script using benchmark-ips and memory_profiler to validate the optimizations. The script sets up tagging configurations and measures the memory usage and execution speed of the tag_content method, confirming the enhancements made in the branch. Overall, this commit contributes to more efficient logging within ActiveRecord, which can lead to better resource utilization in applications.

Files changed

2024-07-23T00:16:51 See commit

This commit resolves errors in the ApplicationTests::QueryLogsTest that arose after a previous commit (#52392). The specific error encountered was a NoMethodError indicating that the method update_formatter was undefined for the ActiveRecord::QueryLogs module. This issue was traced back to the initialization process within the Rails framework, particularly in the railtie.rb file, which failed to find the necessary method during the application's boot process.

To address this, the commit likely includes modifications to ensure that the update_formatter method is properly defined and accessible within the ActiveRecord::QueryLogs module, thereby allowing the test to run successfully. The changes made aim to improve the stability and reliability of the test suite, ensuring that the application behaves as expected after the recent updates to the codebase.

Files changed

2024-07-23T00:56:13 See commit

The commit focuses on improving the handling of multi-statement results in the Trilogy adapter for ActiveRecord. Previously, the code attempted to clear extra results within a with_raw_connection block, which led to complications, particularly when dealing with fresh, non-sticky connections that required a network round trip due to the verify! call before invoking next_result. The new approach simplifies this process by ensuring that results from multi-statement queries are discarded on the same connection used for the query, thereby eliminating unnecessary connection management and enhancing performance.

Key changes include the removal of the previous implementation that cleared results within the select_all method and the execution of next_result calls directly within the raw_execute method. This adjustment streamlines the code, reducing the number of lines and improving clarity while ensuring that multi-statement results are consistently discarded without causing additional overhead. Overall, the commit enhances the efficiency and reliability of executing multi-statement queries in the Trilogy adapter.

Files changed

  • activerecord/lib/active_record/connection_adapters/trilogy/database_statements.rb
2024-07-23T05:56:23 See commit

This commit addresses an issue in the QueryLogsTest related to the test_sql_commenter_format. The update resolves discrepancies in the test specifications, ensuring that the SQL commenter format behaves as expected.

Additionally, the changes made in this commit are in response to issue #52400, indicating that the adjustments were necessary to align the test outcomes with the intended functionality. Overall, the modifications enhance the reliability of the test suite, contributing to improved code quality and maintainability.

Files changed

2024-07-23T23:24:00 See commit

This commit addresses the handling of multi-statement results in the MySQL2 adapter by ensuring that results are consistently discarded. It aligns the behavior with the Trilogy adapter, emphasizing the importance of using the abandon_results! method on the original connection to effectively manage resources. The implementation is optimized by incorporating this logic directly within the raw_execute method, ensuring that any multi-statement results are properly discarded to prevent potential memory leaks or connection issues.

Overall, the changes enhance the robustness of the MySQL2 adapter's handling of multi-statement queries, ensuring that resources are managed efficiently and consistently across different database interactions.

Files changed

2024-07-25T11:18:58 See commit

This commit addresses an issue in the test command where it incorrectly exited with a status code of 0 upon encountering a LoadError. The change ensures that the command will now exit with a status code of 1 when a test file fails to load, indicating an error. Additionally, the commit modifies the behavior of the DidYouMean search to only trigger when the specific test file fails to load, rather than for any underlying require call that may have failed.

The adjustments made in this commit enhance the error handling of the test command, providing clearer feedback to users when a test file cannot be loaded, and ensuring that the exit status accurately reflects the failure. This update follows up on a previous pull request aimed at improving the robustness of the testing framework in Rails.

Files changed