mercredi 26 décembre 2018

How to fix a 'SystemStackError: stack level too deep' error with a large amount of ActiveRecord conditions

I have an ActiveRecord query which iteratively adds or conditions to a search:

places.each do |place|
  people = people.or(People.within_radius_of(place.latitude, place.longitude, place.radius).select(:id))
end

within_radius_of is a custom Postgresql query to find people within a radius.

This works without issue with our original max target of 100 places, but 600 places were added to a search and I get the stack level too deep issue.

What are the implications of increasing the stack size? Default is 1MB, for example what issues might occur if I set it to 8MB or more?

Can this query be rewritten to avoid the error?

Aucun commentaire:

Enregistrer un commentaire