-
-
Notifications
You must be signed in to change notification settings - Fork 473
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
Adds query for all an organization's items to the CSV export service, updates spec to test new behavior #4070
Adds query for all an organization's items to the CSV export service, updates spec to test new behavior #4070
Conversation
… updates spec to test new behavior
end | ||
|
||
@item_headers = item_names.sort | ||
@item_headers = @organization.items.uniq.sort_by(&:created_at).pluck(:name) |
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.
This isn't doing what you think it is :) It's first loading all items into memory and then sorting and mapping them. I think you wanted
@item_headers = @organization.items.order(:created_at).distinct.select([:created_at, :name]).map(&:name)
which does it purely in the database.
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.
For posterity: My comment came across as condescending. A better wording would be something like: "This is doing queries in the app instead of in the database; it would be much faster to do the query this way."
@@ -141,6 +141,7 @@ | |||
|
|||
context "csv" do | |||
let(:response_format) { 'csv' } | |||
before { create(:distribution, partner: partner) } |
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.
Why was this added? It doesn't seem relevant to the PR.
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.
Without creating a distro for the partner, the export method that's called in the csv format fails with nil
distributions. Instead let me put a nil catch in the export.
|
||
let(:total_item_quantities) do | ||
template = item_names.index_with(0) | ||
# binding.pry |
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.
This line can be removed.
f6ea450
to
3ff6b67
Compare
…ibutions is blank, TODO about error-handling
3ff6b67
to
3068bc8
Compare
@dorner ready for re-review, but there's a TODO with a question about how we want to handle errors if someone tries to create a CSV for a list of 0 distributions, so this is still WIP, let me know how to proceed. |
The zero case should still be valid - we should export a CSV with the header row correctly but no rows beneath it. |
Good call! I will fix that. |
@dorner - should be all set, can you take a look? |
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.
Looks good - thanks!
@cielf did you want to take a look before merging? |
Will do -- I've got a pile of reviews to go through tomorrow, I think. FYI @katlovescode -- we usually split the review tasks up so that @dorner makes sure it's technically sound, and then I do some light manual testing to make sure that it's doing what we meant it to do when we wrote up the issue - that nothing got lost in translation. |
LGTM. Merging. Thanks @katelovescode ! |
@katelovescode: Your PR |
Checklist:
Resolves #3388
Description
One concern I have is that Bullet is yelling about eager loading items. I looked through the stack trace and tried to investigate which
includes
was the culprit, but removing the likeliest ones didn't solve the issue. I know Bullet can be finicky, but I'm including the stack trace below. My theory is that it's included somewhere in a scope and we don't need it all the time, so Bullet yells on some queries that use that scope. Not sure if that's important to fix or not. Also it's referencing theGET /diaper_bank/distrbutions.csv
endpoint, which by all accounts doesn't exist, so I'm a little baffled.List any dependencies that are required for this change. (gems, js libraries, etc.)
Type of change
How Has This Been Tested?
Ran local server and downloaded distributions to ensure it showed all columns, with 0s for items that weren't on any of the requested distributions. An easy way to reproduce is to filter to one day, and then see any columns with 0s in them.
Also rspec tests for the behavior.