Skip to content
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

Speed up entry creation (#400) #491

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions app/controllers/projects_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ def index
@hours_entry = Hour.new
@mileages_entry = Mileage.new
@activities = Hour.by_last_created_at.limit(30)
@last_hour_logged = current_user.hours.by_last_updated_at.first
@last_mileage_logged = current_user.mileages.by_last_updated_at.first
end

def show
Expand Down
1 change: 1 addition & 0 deletions app/models/hour.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ class Hour < Entry
accepts_nested_attributes_for :taggings

scope :by_last_created_at, -> { order("created_at DESC") }
scope :by_last_updated_at, -> { order("updated_at DESC") }

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Style/StringLiterals: Prefer single-quoted strings when you don't need string interpolation or special symbols.

scope :by_date, -> { order("date DESC") }
scope :billable, -> { where("billable").joins(:project) }
scope :with_clients, -> {
Expand Down
1 change: 1 addition & 0 deletions app/models/mileage.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

class Mileage < Entry
scope :by_last_created_at, -> { order("created_at DESC") }
scope :by_last_updated_at, -> { order("updated_at DESC") }

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Style/StringLiterals: Prefer single-quoted strings when you don't need string interpolation or special symbols.

scope :by_date, -> { order("date DESC") }
scope :billable, -> { where("billable").joins(:project) }
scope :with_clients, -> {
Expand Down
8 changes: 4 additions & 4 deletions app/views/application/_hours_entry_form.html.haml
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
= simple_form_for @hours_entry do |f|
= f.error_notification
= f.association :project, required: true, collection: Project.unarchived.by_name, label: false, placeholder: t("entries.index.project")
= f.association :category, required: true, collection: Category.by_name, label: false, placeholder: t("entries.index.category")
= f.input :value, required: true, label: false, placeholder: t("entries.index.hours")
= f.association :project, required: true, collection: Project.unarchived.by_name, label: false, placeholder: t("entries.index.project"), selected: @last_hour_logged&.project_id || @hours_entry&.project_id

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Avoid using instance variables in partials views
Line is too long. [206/80]

= f.association :category, required: true, collection: Category.by_name, label: false, placeholder: t("entries.index.category"), selected: @last_hour_logged&.category_id || @hours_entry&.category_id

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Avoid using instance variables in partials views
Line is too long. [200/80]

= f.input :value, required: true, label: false, placeholder: t("entries.index.hours"), input_html: { value: @last_hour_logged&.value || @hours_entry&.value }

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Avoid using instance variables in partials views
Line is too long. [159/80]

= f.input :date, required: true, as: :string, input_html: { value: (@hours_entry.date || DateTime.current).strftime("%d/%m/%Y"), class: "datepicker"}, label: false
.taggable
= f.input :description, input_html: { data: { data: Tag.list }, autocomplete: :off }, label: false, autocomplete: "off", placeholder: t("entries.index.description")
= f.input :description, input_html: { data: { data: Tag.list }, autocomplete: :off }, label: false, autocomplete: "off", placeholder: t("entries.index.description"), input_html: { value: @last_hour_logged&.description || @hours_entry&.description }

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Avoid using instance variables in partials views
Line is too long. [252/80]

%span.background-highlighter
= f.button :submit, data: { disable_with: t("loader.saving") }
4 changes: 2 additions & 2 deletions app/views/application/_mileages_entry_form.html.haml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
= simple_form_for @mileages_entry do |f|
= f.error_notification
= f.association :project, required: true, collection: Project.unarchived.by_name, label: false, placeholder: t("entries.index.project")
= f.input :value, required: true, as: :integer, label:false, placeholder: t("entries.index.mileages")
= f.association :project, required: true, collection: Project.unarchived.by_name, label: false, placeholder: t("entries.index.project"), selected: @last_mileage_logged&.project_id || @mileages_entry&.project_id

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Line contains trailing whitespace
Avoid using instance variables in partials views
Line is too long. [213/80]

= f.input :value, required: true, as: :integer, label:false, placeholder: t("entries.index.mileages"), input_html: { value: @last_mileage_logged&.value || @mileages_entry&.value }

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Avoid using instance variables in partials views
Line is too long. [181/80]

= f.input :date, required: true, as: :string, input_html: { value: (@mileages_entry.date || DateTime.current).strftime("%d/%m/%Y"), class: "datepicker"}, label: false
= f.button :submit, data: { disable_with: t("loader.saving") }
10 changes: 10 additions & 0 deletions spec/models/hour_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,16 @@
end
end

describe "#by_last_updated_at" do

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Style/StringLiterals: Prefer single-quoted strings when you don't need string interpolation or special symbols.

it "orders the entries by updated_at" do

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Style/StringLiterals: Prefer single-quoted strings when you don't need string interpolation or special symbols.

initial_hour = create(:hour)
Timecop.scale(600)
create(:hour)
initial_hour.update_attribute(:value, 2)
expect(Hour.by_last_updated_at.first).to eq(initial_hour)
end
end

describe "#by_date" do
it "orders the entries by date (latest first)" do
create(:hour, date: Date.new(2014, 01, 01))
Expand Down
10 changes: 10 additions & 0 deletions spec/models/mileage_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,16 @@
end
end

describe "#by_last_updated_at" do

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Style/StringLiterals: Prefer single-quoted strings when you don't need string interpolation or special symbols.

it "orders the entries by updated_at" do

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Style/StringLiterals: Prefer single-quoted strings when you don't need string interpolation or special symbols.

initial_hour = create(:mileage)
Timecop.scale(600)
create(:mileage)
initial_hour.update_attribute(:value, 2)
expect(Mileage.by_last_updated_at.first).to eq(initial_hour)
end
end

describe "by_date" do
it "orders the entries by date (latest first)" do
create(:mileage, date: Date.new(2014, 01, 01))
Expand Down