-
Notifications
You must be signed in to change notification settings - Fork 25
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add a weekly Newsletter for the latest open Bounties #19 #36
Open
clair13
wants to merge
14
commits into
excid3:main
Choose a base branch
from
clair13:newsletter
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 6 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
6a4ad33
Implement Bounty mailer for open bounties
clair13 c2b1105
Add whenever gem for sending scheduled weekly email
clair13 05f7152
Add test for the weekly mailer for open bounties
clair13 4fe13ed
Create scope for the last fifteen open bounties query
clair13 0b469c8
Cleanup the scope to be more flexible
clair13 4ae5709
Remove commented out lines
clair13 8f024e1
Implement Bounty mailer for open bounties
clair13 1d1920e
Add whenever gem for sending scheduled weekly email
clair13 daa03ef
Add test for the weekly mailer for open bounties
clair13 32d63d8
Create scope for the last fifteen open bounties query
clair13 2e5c400
Cleanup the scope to be more flexible
clair13 2e422a5
Remove commented out lines
clair13 b9c16d0
Update the rake task for better memory performance
clair13 04c6c94
Update the rake task for better memory performance
clair13 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
class ApplicationMailer < ActionMailer::Base | ||
default from: "from@example.com" | ||
default from: "no-reply@beginnerbounties.com" | ||
layout "mailer" | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
class BountyMailer < ApplicationMailer | ||
def open_bounty | ||
@user = params[:user] | ||
@bounties = params[:bounties] | ||
mail(to: @user.email, subject: "Here are the latest open bounties") | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<p><strong>The open bounties for this week:</strong></p> | ||
<% @bounties.each do |bounty| %> | ||
<h3><%= bounty.title %></h3> | ||
<p>Amount: <%= bounty.amount %>$</p> | ||
<p><%= link_to "View the source code", bounty.url %></p> | ||
<% end %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -39,7 +39,13 @@ | |
# Don't care if the mailer can't send. | ||
config.action_mailer.raise_delivery_errors = false | ||
|
||
|
||
config.action_mailer.delivery_method = :letter_opener | ||
config.action_mailer.default_url_options = { host: 'localhost', port: 3000} | ||
config.action_mailer.perform_caching = false | ||
config.action_mailer.perform_deliveries = true | ||
|
||
#config.action_mailer.default_options = {from: '[email protected]'} | ||
|
||
# Print deprecation notices to the Rails logger. | ||
config.active_support.deprecation = :log | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
every :sunday, at: '17:00 pm' do | ||
rake "send_bounty_email" | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
desc 'send open bounties email' | ||
task send_bounty_email: :environment do | ||
@bounties = Bounty.open.last(15) | ||
if @bounties.any? | ||
@users = User.all | ||
@users.each do |user| | ||
BountyMailer.with(user: user, bounties: @bounties).open_bounty.deliver_later | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,13 @@ | ||
# Read about fixtures at https://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html | ||
|
||
one: | ||
user: one | ||
title: MyString | ||
url: MyString | ||
amount: MyString | ||
status: MyString | ||
title: First Bounty | ||
url: http://www.google.com/ | ||
amount: 10 | ||
status: open | ||
|
||
two: | ||
user: two | ||
title: MyString | ||
url: MyString | ||
amount: MyString | ||
status: MyString | ||
user: one | ||
title: Second Bounty | ||
url: http://www.firefox.com/ | ||
amount: 32 | ||
status: assigned |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,11 @@ | ||
# Read about fixtures at https://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html | ||
one: | ||
email: [email protected] | ||
first_name: first | ||
last_name: Last | ||
encrypted_password: foobar | ||
|
||
# This model initially had no columns defined. If you add columns to the | ||
# model remove the "{}" from the fixture names and add the columns immediately | ||
# below each fixture, per the syntax in the comments below | ||
# | ||
one: {} | ||
# column: value | ||
# | ||
two: {} | ||
# column: value | ||
two: | ||
email: [email protected] | ||
first_name: second | ||
last_name: Doe | ||
encrypted_password: foo |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
require "test_helper" | ||
|
||
class BountyMailerTest < ActionMailer::TestCase | ||
def setup | ||
@user = users(:one) | ||
@bounties = [bounties(:one)] | ||
end | ||
|
||
test "bounty email" do | ||
mail = BountyMailer.with(user: @user, bounties: @bounties).open_bounty | ||
assert_equal "[email protected]", @user.email | ||
assert_equal "Here are the latest open bounties", mail.subject | ||
assert_equal ["[email protected]"], mail.to | ||
assert_equal ["[email protected]"], mail.from | ||
assert_match bounties.first.title, mail.body.encoded | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# Preview all emails at http://localhost:3000/rails/mailers/bounty_mailer | ||
class BountyMailerPreview < ActionMailer::Preview | ||
def open_bounty | ||
BountyMailer.with(user: User.first, | ||
bounties: Bounty.where(status: "open").last(15)).open_bounty | ||
end | ||
end |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @clair13,
I feel this is performance intensive task (although it is rake task but still) as it will load the entire table into memory, instantiating all the rows; then iterate through the instances.
We can use
find_each
, as it does this in batches, which is more efficient in terms of memory usage.something like below
References
Retrieving Multiple Objects in Batches
ActiveRecord::Batches
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for the suggestion,I fixed it based on your suggestion.