How to add index to a big table of your Rails app
Arkency Blog
by Arkency
3M ago
How to add index to a big table of your Rails app When your application is successful, some of the tables can grow pretty big — I’m looking at you users table. If you’re curious enough, you periodically check how your database performs. If any slow query pops up in the metrics, there’s a great chance that some index is missing. State of the DB engines While most modern database engines can create indexes in an asynchronous, non–blocking manner, it’s good to get familiar with all the exceptions from this rule. I highly recommend reading the documentation of PostgreSQL, MySQL. I’m not sure about ..read more
Visit website
Conditionally Enable GZIP on Heroku with Rack::Deflater: Reduce Response Size Significantly
Arkency Blog
by Arkency
3M ago
Conditionally Enable GZIP on Heroku with Rack::Deflater: Reduce Response Size Significantly If you came here after searching for something like “rack deflater path condition” or “rack deflater if option,” here is your answer: config.middleware.use( Rack::Deflater, :if => lambda do |env, _, _, _| env["PATH_INFO"] == "/your/endpoint/path/here" end ) Just insert this line in your application.rb, and you’re set. We could wrap up this post here, but… But we all know that we should not take a piece of random information from the Internet for granted. No matter what the most advance ..read more
Visit website
How to use Hotwire Turbo Streams effectively?
Arkency Blog
by Arkency
3M ago
How to use Hotwire Turbo Streams effectively? Redirects vs Turbo Streams. Have you ever wondered which approach to take? Should you always redirect? Or should you always use Turbo Streams? Take a look at the following functionality. It moves tasks between tables representing states in a Kanban board. The two approaches that can be used to implement this functionality are the Redirect approach and the Turbo Streams approach. Let’s take a look at the redirect approach first. For developers, it is easy, testable, and last but not least, productive. These are solid advantages that make it very t ..read more
Visit website
Do you tune out Ruby deprecation warnings?
Arkency Blog
by Arkency
6M ago
Do you tune out Ruby deprecation warnings? Looking into deprecation warnings is an essential habit to maintain an up-to-date tech stack. Thanks to the explicit configuration of ActiveSupport::Deprecation in the environment-specific configuration files, it’s quite common to handle deprecation warnings coming from Rails. However, I rarely see projects configured properly to handle deprecation warnings coming from Ruby itself. As we always want to keep both Rails and Ruby up-to-date, it’s crucial to handle both types of deprecation warnings. How does Rails handle its deprecation warnings? In the ..read more
Visit website
How to get burned by 16 years old hack in 2024
Arkency Blog
by Arkency
6M ago
There’s a project I’m consulting on where programmers develop predominantly in cloud environment. This setup simplifies a lot of moving parts and has the benefit of providing everyone homogenous containers to run code. If it runs on my box — it will run on everyone’s box. In that case, that box is Linux-based. It has the drawback of having greater latency and being more resource-constrained than a beefy local machine a developer is equipped with, i.e. MacBook Pro running on Apple Silicon. Recently we’ve upgraded this development environment from Ruby 3.2.2 to Ruby 3.0.0. The process was s ..read more
Visit website
How to add a loading animation to your turbo frame with TailwindCSS
Arkency Blog
by Arkency
6M ago
How to add a loading animation to your turbo frame with TailwindCSS Ever been working on a project and hit a snag? That’s what happened to me recently. I came across a turbo frame that was slow to load and didn’t show any signs of loading. Talk about confusing! Waiting a few eternities for the historic transactions tab to load. The busy attribute of the turbo frame The easiest way to add a loading state to the turbo frame is to insert the loader inside the frame tag. Problem is that it only works on the very first load, after that you’ll see the old content until the new one fully loads. I did ..read more
Visit website
Upcasting events in RailsEventStore
Arkency Blog
by Arkency
7M ago
Upcasting events in RailsEventStore Understanding the domain you are working with often leads to the need to redesign some of the models. Sometimes you’ll need to add or change a concept. Other times, you’ll need to remove a method or event produced by the aggregate. This was the case for us. Our goal was to remove an event from the system. To do this, we had to deal with the fact that this event was in the aggregate stream. It’s interesting how we got there. We started discussing how to implement a new business feature in the aforementioned model. After tossing around a few ideas it felt like ..read more
Visit website
Completely custom Zeitwerk inflector
Arkency Blog
by Arkency
7M ago
Completely custom Zeitwerk inflector In my previous post, I discussed the difference between how the classic autoloader and Zeitwerk autoloader match constant and file names. Short reminder: Classic autoloader maps missing constant name Raport::PL::X123 to a file name by calling Raport::PL::X123.to_s.underscore Zeitwerk autoloader finds lib/report/pl/x123/products.rb and maps it to Report::PL::X123::Products constant name with the help of defined inflectors rules. What is an inflector? In general, an inflector is a software component responsible for transforming words according to predefined ..read more
Visit website
The mysterious litany of require_dependecy calls
Arkency Blog
by Arkency
7M ago
The mysterious litany of require_dependecy calls One of the challenges we faced when working on a huge legacy app tech stack upgrade was switching from the obsolete classic autoloader to the modern one, Zeitwerk. It is optional starting from Rails 6 but gets mandatory in Rails 7. Once, we were on Rails 6 and managed to apply most of the new framework defaults, we decided it was high time to switch to Zeitwerk. …This is where the story begins… Spending a lot of time with this codebase we came across one very large initializer with above 300 of require_dependency calls. The first red flag was th ..read more
Visit website
Repository implementation on ActiveRecord
Arkency Blog
by Arkency
9M ago
Repository implementation on ActiveRecord In its essence, a Repository separates domain objects from how they’re persisted and provides a limited interface to access them. It’s a tactical pattern described with far more words by Fowler and Evans than I’d like to include in this introduction. It stands in complete opposition to what ActiveRecord pattern promotes. Why bother transforming one into another? The problem with ActiveRecord pattern comes from its greatest strength. It’s a double-edged sword. Immensely useful in rapid prototyping for a “solopreneur”. Flexible for a well-knit and discip ..read more
Visit website

Follow Arkency Blog on FeedSpot

Continue with Google
Continue with Apple
OR