Our #devs
channel is a cross-project, shared space where the entire dev team of SINAPTIA can ask questions, share opinions, and discuss interesting articles or tech they come across. The idea is to post a curated extract of what happens there every week.
Speeding up data migrations
At Rightboat, the team is working on a data migration process that is slow because it requires restoring a database dump from production, running the migration, and verifying if everything went correctly. If something goes wrong, they need to fix the issue and start over. On Fernando’s laptop, restoring a database dump takes more than an hour, making the entire restore-run-verify cycle extremely time-consuming.
Looking for a solution, Fernando found docker-volume-snapshot, a utility that allows creating and restoring snapshots of Docker volumes. This way, instead of restoring the database, he would create a snapshot of the volume containing the database data and restore it before re-running the migration.
This approach has one disadvantage: the container must be stopped to create and restore snapshots. However, the benefit is significant: restoring a volume only takes less than three minutes.
Upgrading from Classic to Zeitwerk
Tomás is upgrading a Ruby on Rails application. He’s not only upgrading Ruby from 2.8 to 3.2 but also moving from Rails 6.x to 7.1. The most complex part of this upgrade involves switching the autoloader from classic mode to zeitwerk mode. The complexity arises because some acronyms are treated differently between these modes.
For example, in classic mode, a file named url.rb
might contain the URL
class definition. In contrast, zeitwerk mode expects the class name to be Url
.
Patricio shared the official guide, that explains it very well:
Take, for example, the file app/models/vat.rb
. It defines a VAT
class in classic mode. In zeitwerk mode, however, the expected class definition would be Vat
.
The classic autoloader is able to autoload VAT
because its input is the name of the missing constant, VAT
, invokes underscore on it, which yields vat
, and looks for a file called vat.rb
. It works.
The input of the new autoloader is the file system. Given the file vat.rb
, Zeitwerk invokes camelize on vat
, which yields Vat
, and expects the file to define the constant Vat
.
To address these issues, Tomás added acronyms to his project configuration. However, some APIs and serializers still used fields such as imageURL
instead of imageUrl
. Since this is a large project, changing every instance would be tedious, so he asked for advice on the best approach.
Nazareno suggested avoiding acronyms altogether and standardizing class names and inflections according to zeitwerk expectations. This process can be slow but ultimately pays off in terms of maintainability.
Quick link dump
RAG (Retrieval-Augmented Generation) strategies
Fernando shared a couple of articles about chunking strategies for populating indexes in vector databases:
- https://www.anthropic.com/news/contextual-retrieval
- https://research.trychroma.com/evaluating-chunking
Bundle Install Speed Optimization
This tweet from RubyAcademy has a hack for speeding up bundle install using the MAKE environment variable and nproc.
Nokolexbor
Fernando shared a drop-in replacement for Nokogiri he’s using in a web crawler. It’s significantly faster:
Debugging inside vscode
Fernando shared this tweet about setting up vscode’s debugging UI for ruby and called for opinions:
Patricio, Julian and Fernando himself all agreed that debugger
or byebug
plus good-old puts debugging were more than enough. By the way, if you are a puts debuggerer too, check out punchy_pp.
That’s it for this issue. See you around next week!