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
+12
-6
@@ -68,20 +68,26 @@ class GpxStoreTest < Minitest::Test
|
||||
assert_empty @store.tree["children"].reject { |c| c["name"] == "archive" }
|
||||
end
|
||||
|
||||
def test_geojson_is_cached_alongside_the_source_file
|
||||
def test_save_eagerly_caches_the_geojson_conversion
|
||||
path = @store.save(folder: "", filename: "ride.gpx", io: StringIO.new(sample_gpx))
|
||||
cache_path = @store.resolve_file(path) + ".geojson"
|
||||
refute File.file?(cache_path)
|
||||
|
||||
first = @store.geojson(path)
|
||||
assert File.file?(cache_path)
|
||||
|
||||
# Corrupt the cache directly to prove the second call reused it instead
|
||||
# of re-parsing the (still-valid) source file.
|
||||
first = @store.geojson(path)
|
||||
|
||||
# Corrupt the cache directly to prove the call above reused it instead of
|
||||
# re-parsing the (still-valid) source file.
|
||||
File.write(cache_path, first.sub("waypoint", "cached-waypoint"))
|
||||
assert_includes @store.geojson(path), "cached-waypoint"
|
||||
end
|
||||
|
||||
def test_save_of_an_unparseable_file_still_succeeds
|
||||
path = @store.save(folder: "", filename: "bad.gpx", io: StringIO.new("not gpx at all"))
|
||||
|
||||
refute File.file?(@store.resolve_file(path) + ".geojson")
|
||||
assert_raises(Maptool::Gpx::ParseError) { @store.geojson(path) }
|
||||
end
|
||||
|
||||
def test_geojson_cache_is_invalidated_when_the_file_is_resaved
|
||||
path = @store.save(folder: "", filename: "ride.gpx", io: StringIO.new(sample_gpx))
|
||||
@store.geojson(path)
|
||||
|
||||
Reference in new issue
Block a user