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

"Shelters Needing Updates" view fixes #28

Merged

Conversation

nihonjinrxs
Copy link
Member

This does the following:

Review appreciated. These are pretty simple fixes, so I don't expect anything to break.


def outdated
@outdated, @filters = apply_params(
Shelter.where("updated_at < ?", 4.hours.ago).order('updated_at DESC'),
Copy link
Collaborator

Choose a reason for hiding this comment

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

Just some food for thought (not a review). This query is a good candidate for a scope Shelter.outdated. The definition would be placed in the Shelter model after the after_commit callback:

scope :outdated, ->(timing = 4.hours.ago) { where("updated_at < ?", timing) }

Copy link
Member Author

Choose a reason for hiding this comment

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

Nice, hadn't used those before. I'll take a look at that.

@@ -0,0 +1,13 @@
json.cache! @outdated do
Copy link
Collaborator

Choose a reason for hiding this comment

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

I don't see any configuration for a cache expiration time. Unless I have missed it (very possible) json.cache! will cache indefinitely. Adding an expires_in parameter is probably smart. Also, how do we invalidate the cache if an update is made before expiration?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Also curious about why you didn't keep @shelters as the variable. Would have allowed you to keep the same variable for apply_params function instead of replaces the instance variables with local variables.

Copy link
Member Author

Choose a reason for hiding this comment

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

Started out trying to be explicit, and things got deeper and deeper. I may switch this back and clean that up. I do like the refactoring of apply_params, so I'll likely keep that anyway.

Regarding cache, I'm just mimicking what's there already. I agree we should probably look at that, but I think that's a new issue unrelated to this, and should have it's own PR.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Just did a little digging with fresh eyes and found that caching isn't even enabled in either development or production.


private

def apply_params(shelters, params)
Copy link
Collaborator

Choose a reason for hiding this comment

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

You don't need to pass params here, the params object is accessible anywhere in the controller.

Copy link
Member Author

Choose a reason for hiding this comment

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

Sorry, all my work with functional languages coming through. Will fix.

@nihonjinrxs
Copy link
Member Author

OK, I think things here are ready to go. Appreciate a review, and if there's nothing else to do, an approval. Thanks!

@miklb miklb merged commit c21985f into hurricane-response:master Sep 16, 2018
@nihonjinrxs nihonjinrxs deleted the shelters-needing-updates-fixes branch September 17, 2018 00:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants