[openstreetmap/openstreetmap-website] Trace import: remove activerecord-import gem (PR #5038)
Tom Hughes
notifications at github.com
Sun Aug 4 11:34:50 UTC 2024
@tomhughes requested changes on this pull request.
Overall the big difference between `import!` and `insert_all!` is that the former runs validations and the latter does not so maybe if we're going to change we should run `validate!` on each point after it is created?
Really the ideal way to use `insert_all!` would be not to build the models at all and just build a list of hashes but as it stands we need to run the save callbacks to fill in the tile number...
> @@ -71,6 +71,7 @@ Rails/SkipsModelValidations:
Exclude:
- 'db/migrate/*.rb'
- 'app/controllers/users_controller.rb'
+ - 'app/models/trace.rb'
Why do we need to exclude this?
> tracepoints.each do |tp|
tp.run_callbacks(:save) { false }
tp.run_callbacks(:create) { false }
end
- Tracepoint.import!(tracepoints)
+ Tracepoint.insert_all!(tracepoints.map(&:attributes))
I've done some testing and I think this looks right - my main concern is the timestamp column as `attributes` returns it in string form.
It would probably be a good idea to add a test to the trace model tests that imports `a.gpx` and checks that the one point it imports has the expected values for each attribute as we don't seem to have one that checks the imported data at the moment.
--
Reply to this email directly or view it on GitHub:
https://github.com/openstreetmap/openstreetmap-website/pull/5038#pullrequestreview-2217654589
You are receiving this because you are subscribed to this thread.
Message ID: <openstreetmap/openstreetmap-website/pull/5038/review/2217654589 at github.com>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.openstreetmap.org/pipermail/rails-dev/attachments/20240804/437f223c/attachment.htm>
More information about the rails-dev
mailing list