From 932d0b5a6cedbd7e2f6a1694e9d00c9271b4b23e Mon Sep 17 00:00:00 2001 From: Andrew White Date: Thu, 2 Nov 2023 05:58:06 +0000 Subject: [PATCH 1/4] Use rake jobs:work to process jobs in docker --- docker-compose.yml | 37 ++++++++++++++++++------------------- 1 file changed, 18 insertions(+), 19 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index 505cbcaca..65312bc44 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -3,13 +3,6 @@ version: "3.7" x-application: &application image: e-petitions/ruby build: docker/ruby - environment: - - DATABASE_URL=postgres://postgres:ZW4IvOPrXcbp2hyp@postgres:5432 - - MEMCACHE_SERVERS=memcached:11211 - - SMTP_HOST=mailcatcher - - SMTP_PORT=1025 - - SPROCKETS_CACHE=/cache - - PIDFILE=/tmp/pids/server.pid volumes: - .:/app - bundle:/bundle @@ -22,6 +15,14 @@ x-application: &application - mailcatcher - memcached +x-environment: &environment + DATABASE_URL: "postgres://postgres:ZW4IvOPrXcbp2hyp@postgres:5432" + MEMCACHE_SERVERS: "memcached:11211" + SMTP_HOST: "mailcatcher" + SMTP_PORT: "1025" + SPROCKETS_CACHE: "/cache" + PIDFILE: "/tmp/pids/server.pid" + services: postgres: image: postgres:12 @@ -50,6 +51,8 @@ services: web: <<: *application + environment: + <<: *environment command: [ "rails", "server", "-b", "0.0.0.0", @@ -62,21 +65,17 @@ services: worker: <<: *application - command: [ - "bin/delayed_job", "start", - "-p", "worker", - "--min-priority", "10", - "--daemon_options", "-t" - ] + environment: + <<: *environment + MIN_PRIORITY: "10" + command: [ "rake", "jobs:work" ] counter: <<: *application - command: [ - "bin/delayed_job", "start", - "-p", "counter", - "--max-priority", "5", - "--daemon_options", "-t" - ] + environment: + <<: *environment + MAX_PRIORITY: "5" + command: [ "rake", "jobs:work" ] volumes: bundle: From e6bcb6a4e6c0b1ca5d22cf6a2ba573a5702a8dd2 Mon Sep 17 00:00:00 2001 From: Andrew White Date: Thu, 2 Nov 2023 06:05:31 +0000 Subject: [PATCH 2/4] Use exec to execute bundler so that it replaces the wrapper as the main process --- docker/ruby/docker-entrypoint.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docker/ruby/docker-entrypoint.sh b/docker/ruby/docker-entrypoint.sh index 94344de54..69b44b7d9 100755 --- a/docker/ruby/docker-entrypoint.sh +++ b/docker/ruby/docker-entrypoint.sh @@ -16,5 +16,5 @@ else yarn install bundle check || bundle install - bundle exec "$@" + exec bundle exec "$@" fi From 131ce58194fea0d9560741066c4f03c07858801e Mon Sep 17 00:00:00 2001 From: Andrew White Date: Thu, 2 Nov 2023 06:06:29 +0000 Subject: [PATCH 3/4] Archived petitions don't have statistics Since all signatures are anonymised there's no need for subscription stats. --- app/presenters/petition_csv_presenter.rb | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/app/presenters/petition_csv_presenter.rb b/app/presenters/petition_csv_presenter.rb index 8b1a46655..2c8a1a8e3 100644 --- a/app/presenters/petition_csv_presenter.rb +++ b/app/presenters/petition_csv_presenter.rb @@ -58,14 +58,18 @@ def notes petition.note.details if petition.note end + def statistics + petition.respond_to?(:statistics) && petition.statistics + end + def subscriber_count - if petition.statistics.refreshed? + if statistics && statistics.refreshed? csv_escape petition.statistics.subscriber_count end end def subscription_rate - if petition.statistics.refreshed? + if statistics && statistics.refreshed? csv_escape petition.statistics.subscription_rate end end From 901feec1d90832f55ff17746008d6eace2685610 Mon Sep 17 00:00:00 2001 From: Andrew White Date: Thu, 2 Nov 2023 06:24:52 +0000 Subject: [PATCH 4/4] Use `none` to prevent foot-gunning the database Explicitly return an empty result set when no query is present. --- app/models/archived/signature.rb | 4 +++- app/models/signature.rb | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/app/models/archived/signature.rb b/app/models/archived/signature.rb index 4f7c37291..1cb34d5e7 100644 --- a/app/models/archived/signature.rb +++ b/app/models/archived/signature.rb @@ -153,8 +153,10 @@ def search(query, options = {}) scope = scope.for_postcode(query) elsif sector_search?(query) scope = scope.for_sector(query) - else + elsif query.present? scope = scope.for_name(query) + else + scope = scope.none end scope.paginate(page: page, per_page: 50) diff --git a/app/models/signature.rb b/app/models/signature.rb index 774937c8c..605f31407 100644 --- a/app/models/signature.rb +++ b/app/models/signature.rb @@ -255,8 +255,10 @@ def search(query, options = {}) scope = scope.for_postcode(query) elsif sector_search?(query) scope = scope.for_sector(query) - else + elsif query.present? scope = scope.for_name(query) + else + scope = scope.none end scope.paginate(page: page, per_page: 50)