Convert GPX/FIT to GeoJSON at upload time, not first view
GpxStore#save now calls geojson() itself right after writing the file, so the (potentially tens-of-seconds, for a large POI export) conversion cost is paid during the upload — covered by the frontend's existing "Uploading…" status — instead of on whichever checkbox toggle happens to be first, which otherwise reads as a silent hang indistinguishable from broken. An unparseable file still saves fine; the error just surfaces on first view same as before.
This commit is contained in:
1 parent
96065b1237
commit
dd272ffb8a
3 files changed
+34
-8
No files matched your search
@@ -30,12 +30,26 @@ module Maptool
|
||||
# Saves `io`'s contents as a .gpx/.fit file under `folder` (created if
|
||||
# needed), deriving a safe filename from `filename`. Returns the
|
||||
# stored file's path relative to the store root.
|
||||
#
|
||||
# Converts to GeoJSON and caches it right away (see `geojson` below)
|
||||
# rather than waiting for the first time someone checks the file's box —
|
||||
# a several-thousand-waypoint POI export is slow enough to parse that
|
||||
# doing it lazily meant the *first* toggle silently hung (indistinguishable
|
||||
# from broken), instead of the upload's own "Uploading…" status covering
|
||||
# that wait like it already does for the upload itself. A file that fails
|
||||
# to parse still saves fine — same as before, it just surfaces the error
|
||||
# on first view instead of here.
|
||||
def save(folder:, filename:, io:)
|
||||
dir = resolve_dir(folder.to_s)
|
||||
FileUtils.mkdir_p(dir)
|
||||
name = unique_filename(dir, safe_filename(filename))
|
||||
File.binwrite(File.join(dir, name), io.read)
|
||||
relative = folder.to_s.empty? ? name : "#{folder}/#{name}"
|
||||
begin
|
||||
geojson(relative)
|
||||
rescue Gpx::ParseError, Fit::ParseError
|
||||
nil
|
||||
end
|
||||
relative
|
||||
end
|
||||
|
||||
|
||||
Reference in new issue
Block a user