Skip to content

Instantly share code, notes, and snippets.

@eduardopoleo
Last active February 14, 2019 18:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save eduardopoleo/55989a3624546c402b4b171502544cc2 to your computer and use it in GitHub Desktop.
Save eduardopoleo/55989a3624546c402b4b171502544cc2 to your computer and use it in GitHub Desktop.
def recommended_experiences(experiences_limit)
experiences = current_contact
.available_experiences
.includes(challenges: :attachments)
experience_payloads = []
experiences.find_each do |experience|
payload = experience_payload(experience)
empty = payload[:total_challenge_count].zero?
experience_payloads << payload unless empty
break if experience_payloads.size == experiences_limit
end
experience_payloads
end
@eduardopoleo
Copy link
Author

This read better but I do not think it's a great solution cuz find_each could potentially do a bunch of queries.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment