From 07ea52382ae5cc4659593bda83a32b4e30b0e108 Mon Sep 17 00:00:00 2001 From: Sam Poder Date: Tue, 22 Aug 2023 00:58:40 -0700 Subject: [PATCH 01/32] Update digest_mailer.rb --- app/mailers/hackathons/digest_mailer.rb | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/app/mailers/hackathons/digest_mailer.rb b/app/mailers/hackathons/digest_mailer.rb index 8cd92add..6c4bb021 100644 --- a/app/mailers/hackathons/digest_mailer.rb +++ b/app/mailers/hackathons/digest_mailer.rb @@ -32,4 +32,25 @@ def admin_summary(sent_digests) mail to: Hackathons::SUPPORT_EMAIL, cc: User.admins.collect(&:email_address), subject: end + + def organizer_summary(sent_digests) + # This reloads the (possible) sent_digests array as an + # ActiveRecord::Relation so that we can use includes to prevent an N+1. + @sent_digests = Hackathon::Digest.where(id: sent_digests.map(&:id)) || + Hackathon::Digest.where(created_at: 6.days.ago...Time.now) + + @sent_digests_by_hackathons = @sent_digests + .includes(listings: {hackathon: {logo_attachment: :blob}}) + .flat_map(&:listings).group_by(&:hackathon) + .transform_values { |listings| listings.map(&:digest).uniq } + + @listed_hackathons = @sent_digests_by_hackathons.keys + .sort_by { |hackathon| @sent_digests_by_hackathons[hackathon].count }.reverse! + + @listed_hackathons.each do |hackathon| + mail to: hackathon.applicant_email, + subject: "We've just sent your hackathon to #{@digests_by_hackathons[hackathon].count} hackers." + end + + end end From 3ac0e1464badf46318c9013460d3d229c611e54d Mon Sep 17 00:00:00 2001 From: Sam Poder Date: Tue, 22 Aug 2023 01:06:20 -0700 Subject: [PATCH 02/32] Create organizer-summary.html.erb --- .../digest_mailer/organizer-summary.html.erb | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 app/views/hackathons/digest_mailer/organizer-summary.html.erb diff --git a/app/views/hackathons/digest_mailer/organizer-summary.html.erb b/app/views/hackathons/digest_mailer/organizer-summary.html.erb new file mode 100644 index 00000000..df263817 --- /dev/null +++ b/app/views/hackathons/digest_mailer/organizer-summary.html.erb @@ -0,0 +1,13 @@ +<% content_for :greeting do %> +

G'day!

+<% end %> + +

+ We've just sent an email about <%= hackathon.name %> to <%= @digests_by_hackathons[hackathon].count %> hackers. Let us know how things go! +

+ +<% content_for :signature do %> +

+ Best of luck with everything! 🦕 💸 +

+<% end %> From 7e08a8cde8b632af3ae9d2130eb41775c980bdcb Mon Sep 17 00:00:00 2001 From: Sam Poder Date: Tue, 22 Aug 2023 01:06:33 -0700 Subject: [PATCH 03/32] Rename organizer-summary.html.erb to organizer_summary.html.erb --- .../{organizer-summary.html.erb => organizer_summary.html.erb} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename app/views/hackathons/digest_mailer/{organizer-summary.html.erb => organizer_summary.html.erb} (100%) diff --git a/app/views/hackathons/digest_mailer/organizer-summary.html.erb b/app/views/hackathons/digest_mailer/organizer_summary.html.erb similarity index 100% rename from app/views/hackathons/digest_mailer/organizer-summary.html.erb rename to app/views/hackathons/digest_mailer/organizer_summary.html.erb From 325a72e1e301f9638ce6e62d007762c8e58713ef Mon Sep 17 00:00:00 2001 From: Sam Poder Date: Tue, 22 Aug 2023 01:08:04 -0700 Subject: [PATCH 04/32] Update digest_mailer.rb --- app/mailers/hackathons/digest_mailer.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/app/mailers/hackathons/digest_mailer.rb b/app/mailers/hackathons/digest_mailer.rb index 6c4bb021..d0e83760 100644 --- a/app/mailers/hackathons/digest_mailer.rb +++ b/app/mailers/hackathons/digest_mailer.rb @@ -48,6 +48,7 @@ def organizer_summary(sent_digests) .sort_by { |hackathon| @sent_digests_by_hackathons[hackathon].count }.reverse! @listed_hackathons.each do |hackathon| + @hackathon = hackathon # Set the instance variable mail to: hackathon.applicant_email, subject: "We've just sent your hackathon to #{@digests_by_hackathons[hackathon].count} hackers." end From b399e359d839f65b04778bd03a80cea2dfff4c43 Mon Sep 17 00:00:00 2001 From: Sam Poder Date: Tue, 22 Aug 2023 01:08:21 -0700 Subject: [PATCH 05/32] Update organizer_summary.html.erb --- app/views/hackathons/digest_mailer/organizer_summary.html.erb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/hackathons/digest_mailer/organizer_summary.html.erb b/app/views/hackathons/digest_mailer/organizer_summary.html.erb index df263817..14cf0d84 100644 --- a/app/views/hackathons/digest_mailer/organizer_summary.html.erb +++ b/app/views/hackathons/digest_mailer/organizer_summary.html.erb @@ -3,7 +3,7 @@ <% end %>

- We've just sent an email about <%= hackathon.name %> to <%= @digests_by_hackathons[hackathon].count %> hackers. Let us know how things go! + We've just sent an email about <%= @hackathon.name %> to <%= @digests_by_hackathons[@hackathon].count %> hackers. Let us know how things go!

<% content_for :signature do %> From 2d5d748fbb7e77bc6e8116a48d894c822bd6d67c Mon Sep 17 00:00:00 2001 From: Sam Poder Date: Tue, 22 Aug 2023 01:09:06 -0700 Subject: [PATCH 06/32] Update digest_mailer.rb --- app/mailers/hackathons/digest_mailer.rb | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/app/mailers/hackathons/digest_mailer.rb b/app/mailers/hackathons/digest_mailer.rb index d0e83760..6796ced6 100644 --- a/app/mailers/hackathons/digest_mailer.rb +++ b/app/mailers/hackathons/digest_mailer.rb @@ -48,9 +48,10 @@ def organizer_summary(sent_digests) .sort_by { |hackathon| @sent_digests_by_hackathons[hackathon].count }.reverse! @listed_hackathons.each do |hackathon| - @hackathon = hackathon # Set the instance variable - mail to: hackathon.applicant_email, - subject: "We've just sent your hackathon to #{@digests_by_hackathons[hackathon].count} hackers." + @hackathon = hackathon + @count = @digests_by_hackathons[hackathon].count + mail to: hackathon.applicant_email, + subject: "We've just sent your hackathon to #{@count} hackers." end end From 5e4c9f0126e52875be8de366692414f67138819f Mon Sep 17 00:00:00 2001 From: Sam Poder Date: Tue, 22 Aug 2023 01:09:32 -0700 Subject: [PATCH 07/32] Update organizer_summary.html.erb --- app/views/hackathons/digest_mailer/organizer_summary.html.erb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/hackathons/digest_mailer/organizer_summary.html.erb b/app/views/hackathons/digest_mailer/organizer_summary.html.erb index 14cf0d84..774b4a08 100644 --- a/app/views/hackathons/digest_mailer/organizer_summary.html.erb +++ b/app/views/hackathons/digest_mailer/organizer_summary.html.erb @@ -3,7 +3,7 @@ <% end %>

- We've just sent an email about <%= @hackathon.name %> to <%= @digests_by_hackathons[@hackathon].count %> hackers. Let us know how things go! + We've just sent an email about <%= @hackathon.name %> to <%= @count %> hackers. Let us know how things go!

<% content_for :signature do %> From 28474c918cd9066a6b9e8da1057ce7d72ba8103b Mon Sep 17 00:00:00 2001 From: Sam Poder Date: Tue, 22 Aug 2023 01:11:07 -0700 Subject: [PATCH 08/32] Update digest_mailer.rb --- app/mailers/hackathons/digest_mailer.rb | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/app/mailers/hackathons/digest_mailer.rb b/app/mailers/hackathons/digest_mailer.rb index 6796ced6..86733d9d 100644 --- a/app/mailers/hackathons/digest_mailer.rb +++ b/app/mailers/hackathons/digest_mailer.rb @@ -50,9 +50,8 @@ def organizer_summary(sent_digests) @listed_hackathons.each do |hackathon| @hackathon = hackathon @count = @digests_by_hackathons[hackathon].count - mail to: hackathon.applicant_email, - subject: "We've just sent your hackathon to #{@count} hackers." - end - + mail to: hackathon.applicant_email, + subject: "We've just sent your hackathon to #{@count} hackers." + end end end From 994b8e688ef049ab006d42f7248b3ab1a6c153ed Mon Sep 17 00:00:00 2001 From: Sam Poder Date: Tue, 22 Aug 2023 01:12:24 -0700 Subject: [PATCH 09/32] Update digest_mailer.rb --- app/mailers/hackathons/digest_mailer.rb | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/app/mailers/hackathons/digest_mailer.rb b/app/mailers/hackathons/digest_mailer.rb index 86733d9d..98e1058b 100644 --- a/app/mailers/hackathons/digest_mailer.rb +++ b/app/mailers/hackathons/digest_mailer.rb @@ -50,8 +50,7 @@ def organizer_summary(sent_digests) @listed_hackathons.each do |hackathon| @hackathon = hackathon @count = @digests_by_hackathons[hackathon].count - mail to: hackathon.applicant_email, - subject: "We've just sent your hackathon to #{@count} hackers." + mail to: hackathon.applicant_email, subject: "We've just sent your hackathon to #{@count} hackers." end end end From e1e15bf0e1467dcadcb40271c543581cc57f918b Mon Sep 17 00:00:00 2001 From: Sam Poder Date: Tue, 22 Aug 2023 13:50:04 -0700 Subject: [PATCH 10/32] Update digest_mailer.rb --- app/mailers/hackathons/digest_mailer.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/mailers/hackathons/digest_mailer.rb b/app/mailers/hackathons/digest_mailer.rb index 98e1058b..75e659cc 100644 --- a/app/mailers/hackathons/digest_mailer.rb +++ b/app/mailers/hackathons/digest_mailer.rb @@ -50,7 +50,7 @@ def organizer_summary(sent_digests) @listed_hackathons.each do |hackathon| @hackathon = hackathon @count = @digests_by_hackathons[hackathon].count - mail to: hackathon.applicant_email, subject: "We've just sent your hackathon to #{@count} hackers." + mail to: hackathon.applicant.email_address, subject: "We've just sent your hackathon to #{@count} hackers." end end end From 19f309463de8a236e480c54319c6a88cfc92f809 Mon Sep 17 00:00:00 2001 From: Sam Poder Date: Tue, 22 Aug 2023 13:50:13 -0700 Subject: [PATCH 11/32] Update app/mailers/hackathons/digest_mailer.rb Co-authored-by: Gary Tou --- app/mailers/hackathons/digest_mailer.rb | 1 - 1 file changed, 1 deletion(-) diff --git a/app/mailers/hackathons/digest_mailer.rb b/app/mailers/hackathons/digest_mailer.rb index 75e659cc..05c85fca 100644 --- a/app/mailers/hackathons/digest_mailer.rb +++ b/app/mailers/hackathons/digest_mailer.rb @@ -45,7 +45,6 @@ def organizer_summary(sent_digests) .transform_values { |listings| listings.map(&:digest).uniq } @listed_hackathons = @sent_digests_by_hackathons.keys - .sort_by { |hackathon| @sent_digests_by_hackathons[hackathon].count }.reverse! @listed_hackathons.each do |hackathon| @hackathon = hackathon From a23ec8626b2f0b4a15d52520ecc7e0bf0235b1d9 Mon Sep 17 00:00:00 2001 From: Sam Poder Date: Tue, 22 Aug 2023 13:50:39 -0700 Subject: [PATCH 12/32] Update app/views/hackathons/digest_mailer/organizer_summary.html.erb --- app/views/hackathons/digest_mailer/organizer_summary.html.erb | 3 --- 1 file changed, 3 deletions(-) diff --git a/app/views/hackathons/digest_mailer/organizer_summary.html.erb b/app/views/hackathons/digest_mailer/organizer_summary.html.erb index 774b4a08..4088aeb0 100644 --- a/app/views/hackathons/digest_mailer/organizer_summary.html.erb +++ b/app/views/hackathons/digest_mailer/organizer_summary.html.erb @@ -1,6 +1,3 @@ -<% content_for :greeting do %> -

G'day!

-<% end %>

We've just sent an email about <%= @hackathon.name %> to <%= @count %> hackers. Let us know how things go! From c8bf0d4dae73187e8013aeea814ee6030b98f514 Mon Sep 17 00:00:00 2001 From: Sam Poder Date: Tue, 22 Aug 2023 13:52:34 -0700 Subject: [PATCH 13/32] Create organizer_summary.text.erb --- .../hackathons/digest_mailer/organizer_summary.text.erb | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 app/views/hackathons/digest_mailer/organizer_summary.text.erb diff --git a/app/views/hackathons/digest_mailer/organizer_summary.text.erb b/app/views/hackathons/digest_mailer/organizer_summary.text.erb new file mode 100644 index 00000000..b5bdfcae --- /dev/null +++ b/app/views/hackathons/digest_mailer/organizer_summary.text.erb @@ -0,0 +1,5 @@ +We've just sent an email about <%= @hackathon.name %> to <%= @count %> hackers. Let us know how things go! + +<% content_for :signature do %> + Best of luck with everything! 🦕 💸 +<% end %> From 4c25f3a9a48260f62219953b74c0be21a556cccd Mon Sep 17 00:00:00 2001 From: Sam Poder Date: Tue, 22 Aug 2023 15:32:50 -0700 Subject: [PATCH 14/32] Restructure Post-Review --- app/jobs/hackathons/send_digests_job.rb | 2 ++ .../send_organizer_summaries_job.rb | 20 +++++++++++++++++ app/mailers/hackathons/digest_mailer.rb | 22 ++++--------------- 3 files changed, 26 insertions(+), 18 deletions(-) create mode 100644 app/jobs/hackathons/send_organizer_summaries_job.rb diff --git a/app/jobs/hackathons/send_digests_job.rb b/app/jobs/hackathons/send_digests_job.rb index c0ad4f99..999f5857 100644 --- a/app/jobs/hackathons/send_digests_job.rb +++ b/app/jobs/hackathons/send_digests_job.rb @@ -11,7 +11,9 @@ def perform digest.save! unless digest.invalid? && digest.listings.none? sent_digests << digest if digest.persisted? end + ensure + Hackathons::SendOrganizerSummariesJob(sent_digests).perform if sent_digests.any? Hackathons::DigestMailer.admin_summary(sent_digests).deliver_later if sent_digests.any? end diff --git a/app/jobs/hackathons/send_organizer_summaries_job.rb b/app/jobs/hackathons/send_organizer_summaries_job.rb new file mode 100644 index 00000000..3040d910 --- /dev/null +++ b/app/jobs/hackathons/send_organizer_summaries_job.rb @@ -0,0 +1,20 @@ +class Hackathons::SendOrganizerSummariesJob < ApplicationJob + def perform(sent_digests) + # This reloads the (possible) sent_digests array as an + # ActiveRecord::Relation so that we can use includes to prevent an N+1. + @sent_digests = Hackathon::Digest.where(id: sent_digests.map(&:id)) || + Hackathon::Digest.where(created_at: 6.days.ago...Time.now) + + @sent_digests_by_hackathons = @sent_digests + .includes(listings: {hackathon: {logo_attachment: :blob}}) + .flat_map(&:listings).group_by(&:hackathon) + .transform_values { |listings| listings.map(&:digest).uniq } + + @listed_hackathons = @sent_digests_by_hackathons.keys + @listed_hackathons.each do |hackathon| + hackathon = hackathon + sent_digests = @digests_by_hackathons[hackathon] + Hackathons::DigestMailer.admin_summary(sent_digests, hackathon).deliver_later if @sent_digests.any? + end + end +end diff --git a/app/mailers/hackathons/digest_mailer.rb b/app/mailers/hackathons/digest_mailer.rb index 05c85fca..c1459a47 100644 --- a/app/mailers/hackathons/digest_mailer.rb +++ b/app/mailers/hackathons/digest_mailer.rb @@ -33,23 +33,9 @@ def admin_summary(sent_digests) mail to: Hackathons::SUPPORT_EMAIL, cc: User.admins.collect(&:email_address), subject: end - def organizer_summary(sent_digests) - # This reloads the (possible) sent_digests array as an - # ActiveRecord::Relation so that we can use includes to prevent an N+1. - @sent_digests = Hackathon::Digest.where(id: sent_digests.map(&:id)) || - Hackathon::Digest.where(created_at: 6.days.ago...Time.now) - - @sent_digests_by_hackathons = @sent_digests - .includes(listings: {hackathon: {logo_attachment: :blob}}) - .flat_map(&:listings).group_by(&:hackathon) - .transform_values { |listings| listings.map(&:digest).uniq } - - @listed_hackathons = @sent_digests_by_hackathons.keys - - @listed_hackathons.each do |hackathon| - @hackathon = hackathon - @count = @digests_by_hackathons[hackathon].count - mail to: hackathon.applicant.email_address, subject: "We've just sent your hackathon to #{@count} hackers." - end + def organizer_summary(sent_digests, hackathon) + @hackathon = hackathon + @count = sent_digests.count + mail to: hackathon.applicant.email_address, subject: "We've just sent your hackathon to #{@count} hackers." end end From 7e803acf44dcfe43982d3f7f11448f18e4db9226 Mon Sep 17 00:00:00 2001 From: Sam Poder Date: Tue, 22 Aug 2023 22:40:20 +0000 Subject: [PATCH 15/32] Standard --- app/jobs/hackathons/send_digests_job.rb | 1 - .../send_organizer_summaries_job.rb | 32 +++++++++---------- 2 files changed, 16 insertions(+), 17 deletions(-) diff --git a/app/jobs/hackathons/send_digests_job.rb b/app/jobs/hackathons/send_digests_job.rb index 999f5857..b6715c9b 100644 --- a/app/jobs/hackathons/send_digests_job.rb +++ b/app/jobs/hackathons/send_digests_job.rb @@ -11,7 +11,6 @@ def perform digest.save! unless digest.invalid? && digest.listings.none? sent_digests << digest if digest.persisted? end - ensure Hackathons::SendOrganizerSummariesJob(sent_digests).perform if sent_digests.any? Hackathons::DigestMailer.admin_summary(sent_digests).deliver_later if sent_digests.any? diff --git a/app/jobs/hackathons/send_organizer_summaries_job.rb b/app/jobs/hackathons/send_organizer_summaries_job.rb index 3040d910..102f5dda 100644 --- a/app/jobs/hackathons/send_organizer_summaries_job.rb +++ b/app/jobs/hackathons/send_organizer_summaries_job.rb @@ -1,20 +1,20 @@ class Hackathons::SendOrganizerSummariesJob < ApplicationJob def perform(sent_digests) - # This reloads the (possible) sent_digests array as an - # ActiveRecord::Relation so that we can use includes to prevent an N+1. - @sent_digests = Hackathon::Digest.where(id: sent_digests.map(&:id)) || - Hackathon::Digest.where(created_at: 6.days.ago...Time.now) - - @sent_digests_by_hackathons = @sent_digests - .includes(listings: {hackathon: {logo_attachment: :blob}}) - .flat_map(&:listings).group_by(&:hackathon) - .transform_values { |listings| listings.map(&:digest).uniq } - - @listed_hackathons = @sent_digests_by_hackathons.keys - @listed_hackathons.each do |hackathon| - hackathon = hackathon - sent_digests = @digests_by_hackathons[hackathon] - Hackathons::DigestMailer.admin_summary(sent_digests, hackathon).deliver_later if @sent_digests.any? - end + # This reloads the (possible) sent_digests array as an + # ActiveRecord::Relation so that we can use includes to prevent an N+1. + @sent_digests = Hackathon::Digest.where(id: sent_digests.map(&:id)) || + Hackathon::Digest.where(created_at: 6.days.ago...Time.now) + + @sent_digests_by_hackathons = @sent_digests + .includes(listings: {hackathon: {logo_attachment: :blob}}) + .flat_map(&:listings).group_by(&:hackathon) + .transform_values { |listings| listings.map(&:digest).uniq } + + @listed_hackathons = @sent_digests_by_hackathons.keys + @listed_hackathons.each do |hackathon| + hackathon = hackathon + sent_digests = @digests_by_hackathons[hackathon] + Hackathons::DigestMailer.admin_summary(sent_digests, hackathon).deliver_later if @sent_digests.any? + end end end From c633124f85d5585c30052d81a3df8ca9f1dea9c7 Mon Sep 17 00:00:00 2001 From: Sam Poder Date: Tue, 22 Aug 2023 15:41:26 -0700 Subject: [PATCH 16/32] Update send_organizer_summaries_job.rb --- app/jobs/hackathons/send_organizer_summaries_job.rb | 1 - 1 file changed, 1 deletion(-) diff --git a/app/jobs/hackathons/send_organizer_summaries_job.rb b/app/jobs/hackathons/send_organizer_summaries_job.rb index 102f5dda..8f5d6175 100644 --- a/app/jobs/hackathons/send_organizer_summaries_job.rb +++ b/app/jobs/hackathons/send_organizer_summaries_job.rb @@ -12,7 +12,6 @@ def perform(sent_digests) @listed_hackathons = @sent_digests_by_hackathons.keys @listed_hackathons.each do |hackathon| - hackathon = hackathon sent_digests = @digests_by_hackathons[hackathon] Hackathons::DigestMailer.admin_summary(sent_digests, hackathon).deliver_later if @sent_digests.any? end From 8c594d4dd692c92c806f499925409e217ab70491 Mon Sep 17 00:00:00 2001 From: Sam Poder Date: Tue, 22 Aug 2023 23:13:19 -0700 Subject: [PATCH 17/32] Update send_organizer_summaries_job.rb --- app/jobs/hackathons/send_organizer_summaries_job.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/jobs/hackathons/send_organizer_summaries_job.rb b/app/jobs/hackathons/send_organizer_summaries_job.rb index 8f5d6175..bba66ca8 100644 --- a/app/jobs/hackathons/send_organizer_summaries_job.rb +++ b/app/jobs/hackathons/send_organizer_summaries_job.rb @@ -13,7 +13,7 @@ def perform(sent_digests) @listed_hackathons = @sent_digests_by_hackathons.keys @listed_hackathons.each do |hackathon| sent_digests = @digests_by_hackathons[hackathon] - Hackathons::DigestMailer.admin_summary(sent_digests, hackathon).deliver_later if @sent_digests.any? + Hackathons::DigestMailer.organizer_summary(sent_digests, hackathon).deliver_later if @sent_digests.any? end end end From 728b784689eed94bbe1ffca26b0204fd18d4e48d Mon Sep 17 00:00:00 2001 From: Sam Poder Date: Sat, 11 Nov 2023 13:33:27 -0800 Subject: [PATCH 18/32] Update send_organizer_summaries_job.rb Co-authored-by: Matt Almeida --- app/jobs/hackathons/send_organizer_summaries_job.rb | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/app/jobs/hackathons/send_organizer_summaries_job.rb b/app/jobs/hackathons/send_organizer_summaries_job.rb index bba66ca8..7d8fbc24 100644 --- a/app/jobs/hackathons/send_organizer_summaries_job.rb +++ b/app/jobs/hackathons/send_organizer_summaries_job.rb @@ -2,8 +2,7 @@ class Hackathons::SendOrganizerSummariesJob < ApplicationJob def perform(sent_digests) # This reloads the (possible) sent_digests array as an # ActiveRecord::Relation so that we can use includes to prevent an N+1. - @sent_digests = Hackathon::Digest.where(id: sent_digests.map(&:id)) || - Hackathon::Digest.where(created_at: 6.days.ago...Time.now) + @sent_digests = Hackathon::Digest.where(id: sent_digests.map(&:id)) @sent_digests_by_hackathons = @sent_digests .includes(listings: {hackathon: {logo_attachment: :blob}}) From 31243bcf7a3bb332cabd19396b56c3da6325c364 Mon Sep 17 00:00:00 2001 From: Sam Poder Date: Wed, 6 Dec 2023 08:52:18 -0800 Subject: [PATCH 19/32] Update app/mailers/hackathons/digest_mailer.rb Co-authored-by: Matt Almeida --- app/mailers/hackathons/digest_mailer.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/mailers/hackathons/digest_mailer.rb b/app/mailers/hackathons/digest_mailer.rb index fcbaaabf..0d8248a3 100644 --- a/app/mailers/hackathons/digest_mailer.rb +++ b/app/mailers/hackathons/digest_mailer.rb @@ -35,6 +35,6 @@ def admin_summary(sent_digests) def organizer_summary(sent_digests, hackathon) @hackathon = hackathon @count = sent_digests.count - mail to: hackathon.applicant.email_address, subject: "We've just sent your hackathon to #{@count} hackers." + mail to: hackathon.applicant.email_address, subject: "We've just notified #{@count} hackers about #{hackathon.name}!" end end From 331ec677aca318ce03d491498b72a5da1424d9a5 Mon Sep 17 00:00:00 2001 From: Sam Poder Date: Wed, 6 Dec 2023 08:52:28 -0800 Subject: [PATCH 20/32] Update app/views/hackathons/digest_mailer/organizer_summary.html.erb Co-authored-by: Matt Almeida --- app/views/hackathons/digest_mailer/organizer_summary.html.erb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/hackathons/digest_mailer/organizer_summary.html.erb b/app/views/hackathons/digest_mailer/organizer_summary.html.erb index 4088aeb0..b49a38aa 100644 --- a/app/views/hackathons/digest_mailer/organizer_summary.html.erb +++ b/app/views/hackathons/digest_mailer/organizer_summary.html.erb @@ -1,6 +1,6 @@

- We've just sent an email about <%= @hackathon.name %> to <%= @count %> hackers. Let us know how things go! + We've just sent an email about <%= @hackathon.name %> to <%= @count %> hackers.

<% content_for :signature do %> From 1b98f297a55c35ad9f91f24780856cecfcc886df Mon Sep 17 00:00:00 2001 From: Sam Poder Date: Wed, 6 Dec 2023 08:52:34 -0800 Subject: [PATCH 21/32] Update app/views/hackathons/digest_mailer/organizer_summary.text.erb Co-authored-by: Matt Almeida --- app/views/hackathons/digest_mailer/organizer_summary.text.erb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/hackathons/digest_mailer/organizer_summary.text.erb b/app/views/hackathons/digest_mailer/organizer_summary.text.erb index b5bdfcae..ecff71bf 100644 --- a/app/views/hackathons/digest_mailer/organizer_summary.text.erb +++ b/app/views/hackathons/digest_mailer/organizer_summary.text.erb @@ -1,4 +1,4 @@ -We've just sent an email about <%= @hackathon.name %> to <%= @count %> hackers. Let us know how things go! +We've just sent an email about <%= @hackathon.name %> to <%= @count %> hackers. <% content_for :signature do %> Best of luck with everything! 🦕 💸 From 22c52e1f1477ca1f1a95ad450447e80817bc5b77 Mon Sep 17 00:00:00 2001 From: Sam Poder Date: Wed, 6 Dec 2023 08:52:40 -0800 Subject: [PATCH 22/32] Update app/mailers/hackathons/digest_mailer.rb Co-authored-by: Matt Almeida --- app/mailers/hackathons/digest_mailer.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/mailers/hackathons/digest_mailer.rb b/app/mailers/hackathons/digest_mailer.rb index 0d8248a3..4bce48d8 100644 --- a/app/mailers/hackathons/digest_mailer.rb +++ b/app/mailers/hackathons/digest_mailer.rb @@ -32,7 +32,7 @@ def admin_summary(sent_digests) mail to: Hackathons::SUPPORT_EMAIL, cc: User.admins.collect(&:email_address), subject: end - def organizer_summary(sent_digests, hackathon) + def organizer_summary(hackathon, sent_digests) @hackathon = hackathon @count = sent_digests.count mail to: hackathon.applicant.email_address, subject: "We've just notified #{@count} hackers about #{hackathon.name}!" From cf5b9a233214d49a5f146a72d617bd84810968d7 Mon Sep 17 00:00:00 2001 From: Sam Poder Date: Wed, 6 Dec 2023 08:52:46 -0800 Subject: [PATCH 23/32] Update app/jobs/hackathons/send_organizer_summaries_job.rb Co-authored-by: Matt Almeida --- app/jobs/hackathons/send_organizer_summaries_job.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/jobs/hackathons/send_organizer_summaries_job.rb b/app/jobs/hackathons/send_organizer_summaries_job.rb index 7d8fbc24..b27caf23 100644 --- a/app/jobs/hackathons/send_organizer_summaries_job.rb +++ b/app/jobs/hackathons/send_organizer_summaries_job.rb @@ -5,7 +5,7 @@ def perform(sent_digests) @sent_digests = Hackathon::Digest.where(id: sent_digests.map(&:id)) @sent_digests_by_hackathons = @sent_digests - .includes(listings: {hackathon: {logo_attachment: :blob}}) + .includes(listings: :hackathon) .flat_map(&:listings).group_by(&:hackathon) .transform_values { |listings| listings.map(&:digest).uniq } From 115a937a22ec8882061ba7a560d378e5469fa1f4 Mon Sep 17 00:00:00 2001 From: Sam Poder Date: Wed, 6 Dec 2023 09:33:12 -0800 Subject: [PATCH 24/32] Update app/jobs/hackathons/send_organizer_summaries_job.rb --- app/jobs/hackathons/send_organizer_summaries_job.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/jobs/hackathons/send_organizer_summaries_job.rb b/app/jobs/hackathons/send_organizer_summaries_job.rb index b27caf23..4774085a 100644 --- a/app/jobs/hackathons/send_organizer_summaries_job.rb +++ b/app/jobs/hackathons/send_organizer_summaries_job.rb @@ -12,7 +12,7 @@ def perform(sent_digests) @listed_hackathons = @sent_digests_by_hackathons.keys @listed_hackathons.each do |hackathon| sent_digests = @digests_by_hackathons[hackathon] - Hackathons::DigestMailer.organizer_summary(sent_digests, hackathon).deliver_later if @sent_digests.any? + Hackathons::DigestMailer.organizer_summary(hackathon, sent_digests).deliver_later if @sent_digests.any? end end end From 8cb41e44628b44f61f75595af97cc628df4cce92 Mon Sep 17 00:00:00 2001 From: Sam Poder Date: Wed, 6 Dec 2023 09:50:56 -0800 Subject: [PATCH 25/32] Add a test --- .../hackathons/organizer_summary_test.rb | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 test/mailers/hackathons/organizer_summary_test.rb diff --git a/test/mailers/hackathons/organizer_summary_test.rb b/test/mailers/hackathons/organizer_summary_test.rb new file mode 100644 index 00000000..79d39a9b --- /dev/null +++ b/test/mailers/hackathons/organizer_summary_test.rb @@ -0,0 +1,18 @@ +require "test_helper" + +class Hackathons::OrganizerSummaryTest < ActionMailer::TestCase + test "organizer_summary" do + sent_digests = [hackathon_digests(:one)] + hackathon = sent_digests[0].listings[0].hackathon + mail = Hackathons::DigestMailer.organizer_summary(hackathon, sent_digests) + + assert_equal "We've just notified #{sent_digests.count} hackers about #{hackathon.name}!", mail.subject + assert_equal [hackathon.applicant.email_address], mail.to + + assert_match "We've just sent an email about #{hackathon.name} to #{sent_digests.count} hackers.", mail.body.encoded + + # Email CAN-SPAM compliance + assert_match "unsubscribe", mail.body.encoded + assert_match Hackathons::HACK_CLUB_ADDRESS[:full], mail.body.encoded + end +end From 41afc2db4d62d9bff96a147754919032585f6156 Mon Sep 17 00:00:00 2001 From: Sam Poder Date: Wed, 6 Dec 2023 09:54:10 -0800 Subject: [PATCH 26/32] Update organizer_summary_test.rb --- test/mailers/hackathons/organizer_summary_test.rb | 1 - 1 file changed, 1 deletion(-) diff --git a/test/mailers/hackathons/organizer_summary_test.rb b/test/mailers/hackathons/organizer_summary_test.rb index 79d39a9b..05b0ef2a 100644 --- a/test/mailers/hackathons/organizer_summary_test.rb +++ b/test/mailers/hackathons/organizer_summary_test.rb @@ -12,7 +12,6 @@ class Hackathons::OrganizerSummaryTest < ActionMailer::TestCase assert_match "We've just sent an email about #{hackathon.name} to #{sent_digests.count} hackers.", mail.body.encoded # Email CAN-SPAM compliance - assert_match "unsubscribe", mail.body.encoded assert_match Hackathons::HACK_CLUB_ADDRESS[:full], mail.body.encoded end end From 9dec6ae7d25000b27e6a92ad01a9e98dc794149b Mon Sep 17 00:00:00 2001 From: Sam Poder Date: Sun, 24 Dec 2023 15:57:29 -0800 Subject: [PATCH 27/32] Update test/mailers/hackathons/organizer_summary_test.rb Co-authored-by: Matt Almeida --- test/mailers/hackathons/organizer_summary_test.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/mailers/hackathons/organizer_summary_test.rb b/test/mailers/hackathons/organizer_summary_test.rb index 05b0ef2a..1c50e0d4 100644 --- a/test/mailers/hackathons/organizer_summary_test.rb +++ b/test/mailers/hackathons/organizer_summary_test.rb @@ -3,7 +3,7 @@ class Hackathons::OrganizerSummaryTest < ActionMailer::TestCase test "organizer_summary" do sent_digests = [hackathon_digests(:one)] - hackathon = sent_digests[0].listings[0].hackathon + hackathon = hackathon_digests(:one).listings.first.hackathon mail = Hackathons::DigestMailer.organizer_summary(hackathon, sent_digests) assert_equal "We've just notified #{sent_digests.count} hackers about #{hackathon.name}!", mail.subject From 90e38fc7fee9482d10c69ac7a0436536b5da499a Mon Sep 17 00:00:00 2001 From: Sam Poder Date: Mon, 25 Dec 2023 23:24:42 -0800 Subject: [PATCH 28/32] Update app/jobs/hackathons/digests_delivery_job.rb Co-authored-by: Matt Almeida --- app/jobs/hackathons/digests_delivery_job.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/jobs/hackathons/digests_delivery_job.rb b/app/jobs/hackathons/digests_delivery_job.rb index 20a64387..d31aa323 100644 --- a/app/jobs/hackathons/digests_delivery_job.rb +++ b/app/jobs/hackathons/digests_delivery_job.rb @@ -12,7 +12,7 @@ def perform sent_digests << digest if digest.persisted? end ensure - Hackathons::SendOrganizerSummariesJob(sent_digests).perform if sent_digests.any? + Hackathons::SendOrganizerSummariesJob(sent_digests).perform_later if sent_digests.any? Hackathons::DigestMailer.admin_summary(sent_digests).deliver_later if sent_digests.any? end From 8539a84c96ba770046c847156262bbbe9041be5b Mon Sep 17 00:00:00 2001 From: Sam Poder Date: Mon, 25 Dec 2023 23:26:22 -0800 Subject: [PATCH 29/32] rename job --- app/jobs/hackathons/digests_delivery_job.rb | 2 +- app/jobs/hackathons/send_organizer_summaries_job.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/jobs/hackathons/digests_delivery_job.rb b/app/jobs/hackathons/digests_delivery_job.rb index d31aa323..aeef402f 100644 --- a/app/jobs/hackathons/digests_delivery_job.rb +++ b/app/jobs/hackathons/digests_delivery_job.rb @@ -12,7 +12,7 @@ def perform sent_digests << digest if digest.persisted? end ensure - Hackathons::SendOrganizerSummariesJob(sent_digests).perform_later if sent_digests.any? + Hackathons::OrganizerSummaryDeliveriesJob(sent_digests).perform_later if sent_digests.any? Hackathons::DigestMailer.admin_summary(sent_digests).deliver_later if sent_digests.any? end diff --git a/app/jobs/hackathons/send_organizer_summaries_job.rb b/app/jobs/hackathons/send_organizer_summaries_job.rb index 4774085a..62c4feb5 100644 --- a/app/jobs/hackathons/send_organizer_summaries_job.rb +++ b/app/jobs/hackathons/send_organizer_summaries_job.rb @@ -1,4 +1,4 @@ -class Hackathons::SendOrganizerSummariesJob < ApplicationJob +class Hackathons::OrganizerSummaryDeliveriesJob < ApplicationJob def perform(sent_digests) # This reloads the (possible) sent_digests array as an # ActiveRecord::Relation so that we can use includes to prevent an N+1. From 9d7c7442726ce9beee4042efc46abe15dde1978c Mon Sep 17 00:00:00 2001 From: Sam Poder Date: Mon, 25 Dec 2023 23:27:45 -0800 Subject: [PATCH 30/32] move the test --- test/mailers/hackathons/digest_mailer_test.rb | 14 ++++++++++++++ .../hackathons/organizer_summary_test.rb | 17 ----------------- 2 files changed, 14 insertions(+), 17 deletions(-) delete mode 100644 test/mailers/hackathons/organizer_summary_test.rb diff --git a/test/mailers/hackathons/digest_mailer_test.rb b/test/mailers/hackathons/digest_mailer_test.rb index 5b44bf57..854949f0 100644 --- a/test/mailers/hackathons/digest_mailer_test.rb +++ b/test/mailers/hackathons/digest_mailer_test.rb @@ -20,4 +20,18 @@ class Hackathons::DigestMailerTest < ActionMailer::TestCase assert_match "unsubscribe", mail.body.encoded assert_match Hackathons::HACK_CLUB_ADDRESS[:full], mail.body.encoded end + + test "organizer_summary" do + sent_digests = [hackathon_digests(:one)] + hackathon = hackathon_digests(:one).listings.first.hackathon + mail = Hackathons::DigestMailer.organizer_summary(hackathon, sent_digests) + + assert_equal "We've just notified #{sent_digests.count} hackers about #{hackathon.name}!", mail.subject + assert_equal [hackathon.applicant.email_address], mail.to + + assert_match "We've just sent an email about #{hackathon.name} to #{sent_digests.count} hackers.", mail.body.encoded + + # Email CAN-SPAM compliance + assert_match Hackathons::HACK_CLUB_ADDRESS[:full], mail.body.encoded + end end diff --git a/test/mailers/hackathons/organizer_summary_test.rb b/test/mailers/hackathons/organizer_summary_test.rb deleted file mode 100644 index 1c50e0d4..00000000 --- a/test/mailers/hackathons/organizer_summary_test.rb +++ /dev/null @@ -1,17 +0,0 @@ -require "test_helper" - -class Hackathons::OrganizerSummaryTest < ActionMailer::TestCase - test "organizer_summary" do - sent_digests = [hackathon_digests(:one)] - hackathon = hackathon_digests(:one).listings.first.hackathon - mail = Hackathons::DigestMailer.organizer_summary(hackathon, sent_digests) - - assert_equal "We've just notified #{sent_digests.count} hackers about #{hackathon.name}!", mail.subject - assert_equal [hackathon.applicant.email_address], mail.to - - assert_match "We've just sent an email about #{hackathon.name} to #{sent_digests.count} hackers.", mail.body.encoded - - # Email CAN-SPAM compliance - assert_match Hackathons::HACK_CLUB_ADDRESS[:full], mail.body.encoded - end -end From ee65871698308d1a4bf94544e462bf3f6e9cbac2 Mon Sep 17 00:00:00 2001 From: Sam Poder Date: Mon, 25 Dec 2023 23:29:05 -0800 Subject: [PATCH 31/32] that was very bad of me --- ...nizer_summaries_job.rb => organizer_summary_deliveries_job.rb} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename app/jobs/hackathons/{send_organizer_summaries_job.rb => organizer_summary_deliveries_job.rb} (100%) diff --git a/app/jobs/hackathons/send_organizer_summaries_job.rb b/app/jobs/hackathons/organizer_summary_deliveries_job.rb similarity index 100% rename from app/jobs/hackathons/send_organizer_summaries_job.rb rename to app/jobs/hackathons/organizer_summary_deliveries_job.rb From 9adae8e92316427f21df833a5edc56d07012e0bc Mon Sep 17 00:00:00 2001 From: Sam Poder Date: Mon, 25 Dec 2023 23:30:54 -0800 Subject: [PATCH 32/32] run standard and pray --- test/mailers/hackathons/digest_mailer_test.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/test/mailers/hackathons/digest_mailer_test.rb b/test/mailers/hackathons/digest_mailer_test.rb index 854949f0..6a1bf4f5 100644 --- a/test/mailers/hackathons/digest_mailer_test.rb +++ b/test/mailers/hackathons/digest_mailer_test.rb @@ -20,17 +20,17 @@ class Hackathons::DigestMailerTest < ActionMailer::TestCase assert_match "unsubscribe", mail.body.encoded assert_match Hackathons::HACK_CLUB_ADDRESS[:full], mail.body.encoded end - + test "organizer_summary" do sent_digests = [hackathon_digests(:one)] hackathon = hackathon_digests(:one).listings.first.hackathon mail = Hackathons::DigestMailer.organizer_summary(hackathon, sent_digests) - + assert_equal "We've just notified #{sent_digests.count} hackers about #{hackathon.name}!", mail.subject assert_equal [hackathon.applicant.email_address], mail.to - + assert_match "We've just sent an email about #{hackathon.name} to #{sent_digests.count} hackers.", mail.body.encoded - + # Email CAN-SPAM compliance assert_match Hackathons::HACK_CLUB_ADDRESS[:full], mail.body.encoded end