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

Refactor schedule action in distributions_controller for better preformance #4509

Merged
merged 2 commits into from
Jul 19, 2024
Merged
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
9 changes: 8 additions & 1 deletion app/controllers/distributions_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,14 @@ def itemized_breakdown

# TODO: This needs a little more context. Is it JSON only? HTML?
def schedule
@pick_ups = current_organization.distributions
respond_to do |format|
format.html
format.json do
start_at = params[:start].to_datetime
end_at = params[:end].to_datetime
@pick_ups = current_organization.distributions.includes(:partner).where(issued_at: start_at..end_at)
end
end
end

def calendar
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
class AddIssuedAtIndexToDistribution < ActiveRecord::Migration[7.1]
disable_ddl_transaction!

def change
add_index :distributions, :issued_at, algorithm: :concurrently
end
end
3 changes: 2 additions & 1 deletion db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema[7.1].define(version: 2024_07_04_214509) do
ActiveRecord::Schema[7.1].define(version: 2024_07_11_020808) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"

Expand Down Expand Up @@ -244,6 +244,7 @@
t.boolean "reminder_email_enabled", default: false, null: false
t.integer "delivery_method", default: 0, null: false
t.decimal "shipping_cost", precision: 8, scale: 2
t.index ["issued_at"], name: "index_distributions_on_issued_at"
t.index ["organization_id"], name: "index_distributions_on_organization_id"
t.index ["partner_id"], name: "index_distributions_on_partner_id"
t.index ["storage_location_id"], name: "index_distributions_on_storage_location_id"
Expand Down