shlogg · Early preview
Augusts Bautra @augustsbautra

Senior Rails developer from Latvia. Avid gamer. Longevity enthusiast. #keto-dude

Optimizing UNION Queries: From 30s To Under 1s Report Generation Time

Debugging performance issues in reports led to a breakthrough: replacing WHERE field IN with WHERE EXISTS (SELECT 1 ...) improved query time from 30s to under 1s!

Prevent Race Conditions With Retryable In Rails

Wrap .first_or_create!/find_or_create_by! calls in retryable block to prevent race conditions. Use Retryable gem with on: [ActiveRecord::RecordNotUnique, ActiveRecord::RecordInvalid] for a clean solution.

Domain Query Interface In Ruby: A Code Challenge Takeaway

Participated in code challenge despite illness, focusing on Domain Query Interface & entity-based operations. Learned to optimize game state & debugging info for reproducibility.

Buffered Bulk Updates For Efficient Database Operations

Optimizing import logic with buffered bulk updates: collect updates in a buffer, perform upsert_all when reaching batch_size, reducing DB roundtrip overhead and improving performance.

Transactional Specs Reduce CI Run Time Spikes

Parallel RSpec runners on CI took 12-20min due to specs writing to DB & DatabaseCleaner cleanup. Switched from :truncation to :deletion, reducing spikes by 60s. Monitoring run times is key to preventing issues.

Reducing N+1 Queries In Rails 7.1 With Strict Loading

Reduce N+1 queries in Rails v7.1 with `.strict_loading!`. Configure `config/application.rb` and `config/environments/development.rb` to log or raise violations. Chain `.strict_loading` in new controller code, especially actions.

Adding Indexes In Production With Strong Migrations And PGHero

Adding an index in production is relatively safe with `strong_migrations` and `pghero`. Use `ActiveRecord::Migration.add_index` to add concurrently, then remove if it fails. Commit a corresponding migration for all envs.

Skipping Navbar In Feature Specs For Faster CI Runtimes

Experimenting with skipping navbar rendering in feature specs to reduce CI runtime by 2-4%. Created a hook to disable navbar by default, but allow opting back into rendering as needed.

Normalizing Boolean Fields With Rails' Normalize Macro

Normalizes macro doesn't normalize nil values out of the box. Use `:boolean_field, apply_to_nil: true, with: -> { _1.present? }` to fix this issue.

Custom Status Ordering With Rails 7.1 And In_order_of Method

Custom semantic order with SQL CASE or Rails' in_order_of! Use `in_order_of(:status, [:active, :draft], filter: false).order(:id)` for a better way since Rails 7.1.

Rails Has_many Association: Leveraging Genre_ids For Efficient Updates

has_many association in Rails gives 17 methods. Focus on collection_singular_ids=(ids) part which allows mass-assignment of genres for a book.

Custom Matcher For Ignoring Empty Cells In Excel Export Tests

Fixed Excel export tests by creating custom matcher to ignore irrelevant empty cells. Simplified specs and made them more readable.