Skip to content

Instantly share code, notes, and snippets.

I may be slow to respond.

Pau Pérez Fabregat sauloperez

I may be slow to respond.
View GitHub Profile
View questions_with_total_delegates.sql
-- questions + count of its delegated votes
WHEN has_granter THEN count_by_setting_id
END AS total_delegates
View one_less_join.patch
commit 74fb66e93619074dda3bd98cfe935c4ced30143f
Author: Pau Perez <>
Date: Thu Jan 7 12:29:40 2021 +0100
Count occurrences of foreign key instead of join
As we just care for the count of users and not about any of their
details there's no need to join with the users table. The foreign key
column is enough to count.
View improvement.patch
commit b5680a7effab8bb9f1b1542366b6dad36fe23611
Author: Pau Perez <>
Date: Thu Jan 7 11:21:00 2021 +0100
Turn to 2 queries into one with another INNER JOIN
There's no need to fetch the votes' authors first if we can scope the
query to the votes' records we care about in a single statement.
Letting the DB do its job results in less code on our side and better
performance. We skip Ruby CPU cycles and a network round trip for each
sauloperez / cercles-coop.log
Created Nov 19, 2020 stacktrace
View cercles-coop.log
2020-11-19T12:34:41.054839+00:00 app[web.1]: F, [2020-11-19T12:34:41.054744 #34] FATAL -- : [3a52ba07-f9a1-4a7e-bed6-25affba1b729] Rack::Timeout::RequestTimeoutException (Request waited 5ms, then ran for longer than 30000ms ):
2020-11-19T12:34:41.054840+00:00 app[web.1]: F, [2020-11-19T12:34:41.054787 #34] FATAL -- : [3a52ba07-f9a1-4a7e-bed6-25affba1b729]
2020-11-19T12:34:41.054961+00:00 app[web.1]: F, [2020-11-19T12:34:41.054886 #34] FATAL -- : [3a52ba07-f9a1-4a7e-bed6-25affba1b729] vendor/bundle/ruby/2.6.0/gems/excon-0.78.0/lib/excon/socket.rb:279:in `select'
2020-11-19T12:34:41.054962+00:00 app[web.1]: [3a52ba07-f9a1-4a7e-bed6-25affba1b729] vendor/bundle/ruby/2.6.0/gems/excon-0.78.0/lib/excon/socket.rb:279:in `select_with_timeout'
2020-11-19T12:34:41.054962+00:00 app[web.1]: [3a52ba07-f9a1-4a7e-bed6-25affba1b729] vendor/bundle/ruby/2.6.0/gems/excon-0.78.0/lib/excon/socket.rb:140:in `rescue in block in connect'
2020-11-19T12:34:41.054963+00:00 app[web.1]: [3a52ba07-f9a1-4a7e-bed6-25affba1b729] vendor/bundle
sauloperez / signal_catching.rb
Last active Nov 11, 2020
How to catch SIGINT and SIGTERM signals in Ruby
View signal_catching.rb
# Signal catching
def shut_down
puts "\nShutting down gracefully..."
sleep 1
puts "I have PID #{}"
# Trap ^C
Signal.trap("INT") {
sauloperez / development.rb
Created Jul 20, 2020
Complete production-like development-mode profiling environment
View development.rb
Rails.application.configure do
# Settings specified here will take precedence over those in config/application.rb.
# In the development environment your application's code is reloaded on
# every request. This slows down response time but is perfect for development
# since you don't have to restart the web server when you make code changes.
config.cache_classes = !!ENV["PROFILE"]
# Do not eager load code on boot.
config.eager_load = !!ENV["PROFILE"]


Review of the process

We will check epics to see whether the criteria in terms of performance has been met.

Tech and Po check from time to time how we do in terms of reaching the goal and adapting.

Filipe is still finding his way and will share any process improvements as soon as he has grasps it all and has ideas.

sauloperez /
Last active Jun 5, 2019
database dump with compression
pg_dump -U ofn_user -h localhost openfoodnetwork -Fc -f /tmp/production_dump.sql
# openfoodnetwork@production18:~/apps/openfoodnetwork/current$ du -h /tmp/production*
# 320M /tmp/production_dump_with_compression.sql
# 1.2G /tmp/production_dump_without_compression.sql
View .devenv