Rails 6 excitement, connection pool reaping, bug fixes

Greetings! Daniel here, reporting from Brooklyn, NY.

Rails 6 in the wild

I know we mentioned this last week, but I am so excited I wanted to mention it again. Rails 6 has been out for a little over a week and has had over 60,000 downloads. Check it out today!

Ensure connection reaper threads respawn in forks

I didn’t know much about this part of Rails before looking at this PR. The connection pool synchronizes thread access to database connections. The reaper continuously calls reap and flush on the connection pool. I have just one question: can somebody translate Aaron Patterson’s comment for me?

Avoid reaping parent connection pool after fork

This is from the same part of Rails as above. I really enjoyed seeing the collaboration between Guo Xiang Tan and John Hawthorn in these PRs. Nice work!

Fix memoization bug in Active Record

Anmol Arora noticed and fixed an Active Record bug that has been around for years. Excellent work on your first commit to Rails!

29 people contributed to Rails over the past week, including 8 first-timers. Check out the full list of changes, and if you are interested in helping out check out the open issues. Until next time…

Rails 6 is released, sass-rails 6, improved mysql2 error and more

Hello! This is Prathamesh bringing the latest news from the Rails community. This week we have some big news. Get ready.

Rails 6 is out!

After two and half years of development from more than 800 people having staggering 7275 commits, Rails 6 is released. Time to upgrade 😁
Check out the release notes and upgrading guide to know more.

Support for sass-rails 6

Rails now works with sass-rails 6.0. sass-rails 6 wraps sassc-rails gem under the hood. This new version stops usage of outdated and unsupported ruby-sass gem.

Make prepared statement status thread and instance-specific

This fixes a race condition in system tests where prepared
statements can be incorrectly parameterized when multiple
threads observe the mutation of the @prepared_statements
instance variable on the connection.

Improve MySQL error detection

Improve detection of ActiveRecord::StatementTimeout error with mysql2 adapter in the edge case when the query is terminated during file sort.

Log potential matches when asserting active job test helpers

Adds logging of potential matches when calling assert_enqueued_with and assert_performed_with  to provide more information about test failures.

25 people contributed to Rails in the last week. Want to see your name on that list? Check out the list of issues here.

See you next week.

Rails 6.0: Action Mailbox, Action Text, Multiple DBs, Parallel Testing, Webpacker by default, and Zeitwerk

Dealing with incoming email, composing rich-text content, connecting to multiple databases, parallelizing test runs, integrating JavaScript with love, and rewriting the code loader. These are fundamental improvements to the fundamentals of working with the web and building fast and fresh applications. This is the kind of work we’ve been doing for the past fifteen years, and we’re still at it. THIS IS RAILS SIX!

And that’s just the headline improvements! Since Rails 5.2 was released a little over a year ago, we’ve continued our high pace of improvement all over the framework. In 2019 alone, we’ve had 341 code contributors submit improvements and fixes. We’ve tried to summarize just some of the goodies in the release notes, but there are many more than that.

While we took a little while longer with the final version than expected, the time was spent vetting that Rails 6 is solid. In fact, GitHub, Shopify, and Basecamp, as well as plenty of other companies and applications, have been running the pre-release version of Rails 6 for months and months in production. We might not have caught everything, but if it’s good enough for GitHub, Shopify, and Basecamp, it’s probably good enough for you too!

So what are you going to get with Rails 6? Check it out:

Action Mailbox routes incoming emails to controller-like mailboxes for processing in Rails. It ships with ingresses for Mailgun, Mandrill, Postmark, and SendGrid. You can also handle inbound mails directly via the built-in Exim, Postfix, and Qmail ingresses. The foundational work on Action Mailbox was done by George Claghorn and yours truly.

Action Text brings rich text content and editing to Rails. It includes the Trix editor that handles everything from formatting to links to quotes to lists to embedded images and galleries. The rich text content generated by the Trix editor is saved in its own RichText model that’s associated with any existing Active Record model in the application. Any embedded images (or other attachments) are automatically stored using Active Storage and associated with the included RichText model. The foundational work on Action Text was done by Sam Stephenson, Javan Makhmali, and yours truly.

The new multiple database support makes it easy for a single application to connect to, well, multiple databases at the same time! You can either do this because you want to segment certain records into their own databases for scaling or isolation, or because you’re doing read/write splitting with replica databases for performance. Either way, there’s a new, simple API for making that happen without reaching inside the bowels of Active Record. The foundational work for multiple-database support was done by Eileen Uchitelle and Aaron Patterson.

With parallel testing support, you can finally take advantage of all those cores in your machine to run big test suites faster. Each testing worker gets its own database and runs in its own thread, so you’re not pegging one CPU to 100% while the other 9 sit idle by (y’all do have a 10-core iMac Pro, right 😂). Hurray! The foundational work for parallel-testing support was done by Eileen Uchitelle and Aaron Patterson.

Webpacker is now the default JavaScript bundler for Rails through the new app/javascript directory. We’re still using the asset pipeline with Sprockets for CSS and static assets, though. The two integrate very nicely and offer the best trade-off of advanced JavaScript features with an it-just-works approach to other assets.

Xavier Noria’s new Zeitwerk code loader for Ruby. No more const_missing, no more code loading gotchas, hello Module#autoload!

Those are just some of the marque additions, but Rails 6.0 is also packed with minor changes, fixes, and upgrades. Just some I’d call out: Proper Action Cable testing, Action Cable JavaScript rewritten in ES6, protection against DNS rebinding attacks, and per-environment credentials. Also, Rails 6 will require Ruby 2.5.0+ now. You can check out everything in the individual framework CHANGELOG files for the nitty-gritty rundown.

This release was shepherded by release manager Rafael França with support by Kasper Timm Hansen.

Thanks again to everyone who keeps working on making Rails better! Thanks to everyone who uses Rails! I’m incredibly proud to see this open-source framework continue to thrive outside the pressures of market terms and reciprocal guilt. This is a gift we give each other and expect nothing in return.

Rails 6.0.0 rc2 released

The final version of Rails 6.0 is almost ready, but before we put a pin in it, please enjoy this second release candidate. We’ve cleared all the blockers that were discovered during the first release candidate, and if nothing new and major is discovered, we’ll ship the final release in a couple of weeks.

There has been 172 commits of changes since rc1.

You can read all about what’s new in Rails 6.0.0 in the first beta announcement. From Action Mailbox to Action Text, multiple database support, parallel testing, and Webpacker handling JavaScript by default. This is a massive step forward for Rails.

This release, and all releases leading up to Rails 6.0 final, was shepherded by release manager Rafael França with support by Kasper Timm Hansen.

Active Storage, startless range in queries, SMS links and more!

Hello! This is Roque bringing the latest news from the Rails community. It’s been awhile so let’s see what has changed since then… Oops, since last week 😜

Preserve existing attachment assignment behavior for app upgraded to Rails 6.0

Assigning a collection of attachments appends to the collection as it did in 5.2. Existing 5.2 apps that rely on this behavior will no longer break when they’re upgraded to 6.0. For Apps generated on 6.0, assigning replaces the existing attachments in the collection. #attach should be used to add new attachments to the collection without removing existing ones.

Support startless ranges in queries

Add support to startless ranges (e.g. ..10 and ..Date.today), introduced by Ruby 2.7.0-preview1, to Active Record queries. This enables expression like Order.where(created_at: ..1.year.ago).

When the users click the SMS link, their messaging app opens with the phone number and optional message body set in the link.

Superclass for aborted queries

The class ActiveRecord::QueryAborted makes it possible, for example, to rescue all possible query timeouts without rescuing other query exceptions.

Add --skip-collision-check option to the Rails generator

This allows the generator for 6.0 to behave like it used to in 5.2, and overwrite files.

18 people contributed to Rails in the last week. Want to see your name on that list? Check out the list of issues here.

Until next time!

New contributors fixing bugs in the summer

Hey all! This is Daniel from Brooklyn, NY bringing you the latest news in Rails.

Add database_exists? method to connection adapters

The database_exists? method does what you might think—it checks whether a database exists. This will help in resolving some inconsistencies between SQLite and the other database adapters.

Share column and table names between connections

Sharing is a beautiful thing. Since connection instances are likely to share table and column names, we can store them on the class instead of on each instance. Isn’t that nice?

Fix query cache when using shared connections

Congratulations to Heinrich on their first commit to Rails!

Fix bug when combining order with exist?

Congratulations to Takayuki on their first commit to Rails!

21 people contributed to Rails in the last week. Want to see your name on that list? Check out the list of issues here.

Be well!

Schema dump fix and database task creation improvements!

Hi there. This is Greg bringing you latest news from the Rails world. We had a quiet week, so I won’t take long.

Fix schema dumping for enum and set columns in MySQL

With this change Active Record will use the sql_type rather than type, in the database dump for enum and set columns to make sure they use the correct type.

Warn if database tasks can’t be created

With this change, Rails loads the initial database.yml once, and warns if it can’t create tasks. This is important for multiple databases, where the tasks are created for every database, but to create those Rails needs to read the list from database.yml.

9 people contributed to Rails in the last week, if you want to be one of them, check out the list of issues here.

Until next time!

☀️🏖🏄‍♀️ and schema cache deduplication plus getutc begone

Ahoy all! 🚢 Step aboard as we cruise through the Rails news this week. Summer has really hit its simmering point for many a Rails contributor: we’re seeing fewer contributions. Take heed! Your trusty captain Kasper is here to reassure you that nothing has gone wrong on this ship and that it’s merely summer time seasoning. But also, the engine is on fire? Oh well, it’ll probably burn out soon enough and another wrong has been righted! This is fine. 🔥

Schema Cache: deduplicate structures

This week has primarily been a strong one for Active Record’s schema cache with no less than 3 improvements. It’s a little known feature but it avoids querying your database for its schema every time a new server starts up (handy if you’re booting up many app servers). You invoke it with…

Schema Cache: stop serializing and parsing columns_hash

rails schema:cache:dump, check its documentation for more. These 3 changes are around deduplication the memory that the schema cache holds in a running app by doing deduplication. Basically running a uniq on objects and reusing already initialized ones. This technique is uncommon, but effective here, because so many tables share the same columns, e.g. id, created_at, updated_at etc. So the first change…

Schema Cache: deduplicate when using init_with

…ran deduplication for most things in the schema cache. The second change skipped storing the columns_hash in the YML, because it could be derived with columns.index_by(&:name). Thus saving storing every column object again, but just nested under the name. Neat! Rounding out the features: the deduplication should also be run when parsing YML and the parser invoking init_with. Remedied that, phew! I suggest you do check all three changes out because they show to really re-sculpt a feature over multiple PRs.

Active Record: avoid redundant time.getutc when serializing

Lastly, rounding out the news: some more speed ups! Currently serializing a Time attribute will run time.getutc in multiple places regardless of whether the time is already UTC, which is fairly expensive. This change checks if the time is already UTC and won’t bother with any needless conversion. ⏱

21 people contributed to Rails in the last two weeks. You can see the full list of changes here.

Until next time!

Direct upload mirroring, multiple databases overview and more

Hi there. This is Wojtek bringing you goodies from the Rails world.

Document multiple databases

Gives a great overview of available multiple database features coming in Rails 6.

Mirror direct uploads

Tells the mirror service to copy the blob from the primary service to any secondary service where it doesn’t already exist.

Fix preloading on ActiveRecord::Relation

Fixes a case where records are duplicated by a join by using a less known Hash method compare_by_identity.

Improve on_rotation in MessageEncryptor

Allow on_rotation option in MessageEncryptor to be passed in constructor.

Make rescues layout responsive

Debugging on small devices got a lot easier by adjusting default errors layout. Check the pull request for sample image.

51 people contributed to Rails in the last month. You can see the full list of changes here.

Until next time!

Performance improvements, large file uploads to S3 and more!

Hello fellow Rubyist!

This is Greg, bringing the latest news about the Rails framework!

Fill a Trix editor easily in system tests

ActionDispatch::SystemTestCase#fill_in_rich_text_area  can  locate and fill a Trix editor with the given HTML in your system tests.

ActiveRecord#respond_to? performance improvements

The changes introduced by this pull request made ActiveRecord#respond_to?  1.5x faster and it also no longer allocates strings.

Permit uploading files larger than 5 GB to S3

If you are using S3 with Active Storage, now you can upload large files and the services will transparently switch to streaming.

HashWithIndifferentAccess#initialize performance improvement

With this change, a quite expensive to_hash call is bypassed in the constructor if we are already dealing with a hash.

Expose mailbox_for method in ApplicationMailbox

Rails 6 is bringing Action Mailbox and with this change, it will be possible to check which mailbox an email is routed to without processing it.

40 people contributed to Rails in the last week. If you want to be part of that, check out the list of open issues.

Until next time!