Performance: Association callbacks
MEDIUM IMPACT
This affects server response time and database transaction speed during object creation or update involving associated records.
class Order < ApplicationRecord has_many :items after_add :enqueue_processing def enqueue_processing(item) ProcessingJob.perform_later(item.id) end end
class Order < ApplicationRecord has_many :items after_add :heavy_processing def heavy_processing(item) # complex calculations or external API calls sleep(2) # simulating delay end end
| Pattern | Database Calls | Transaction Blocking | Server Response Time | Verdict |
|---|---|---|---|---|
| Heavy logic in association callbacks | 1+ per callback | Blocks until complete | High latency | [X] Bad |
| Light callbacks delegating to background jobs | 1 minimal call | Non-blocking | Low latency | [OK] Good |