geokit / geokit-rails

Official Geokit plugin for Rails/ActiveRecord. Provides location-based goodness for your Rails app. Requires the Geokit gem.
MIT License
1.57k stars 245 forks source link

sqlserver.rb is too heavy #70

Open kwerle opened 9 years ago

kwerle commented 9 years ago

The sqlserver adapter drops and creates a function every time the class is loaded.

In a corporate production environment, dropping and adding functions is often strictly controlled.

What's more, if you're running more than one instance of the app, there is a chance that instance 2 will fire up and drop the function while instance 1 is trying to use the function.

Finally, if you're using flat_distance_sql instead of sphere_distance_sql, you will never need the created function.

For all these reasons, I think the creation of that sql function should be a class method, not run on load. It should be a one-time operation for any database that the developer should be responsible for running - say in a migration or what have you. Ideally you should catch the appropriate sql error that would result from calling sphere_distance_sql without that method and document what the developer needs to do to make it work.

p.s. I hate sql server for not having a least function.