Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Improve OSM GeoJson data loading pipeline #72

Draft
wants to merge 12 commits into
base: main
Choose a base branch
from

Conversation

2kai2kai2
Copy link
Contributor

Improvements to the way the Soundscape app handles the GeoJson data it receives from our services.

I have a few likely goals:

  • Update JSON parsing from legacy Objective-C methods
  • Caching strategy (Realm) needs to be looked at, as deprecated tools are currently used
  • Switch from callbacks to async where possible to simplify control flow
  • Tests to ensure data is retrieved and parsed properly from servers

Sometimes failing due to issues with voices.
The previous strategy used for parsing the OSM GeoJson data received from our services was based on old Objective-C compatibility, which is generally no longer needed. Replacing it provides significant simplification and type safety.

First, we now use `JSONDecoder` and the `Decodable` protocol to parse GeoJson data, rather than the old (NS)JSONSerialization strategy.

Second, `GeometryType` and `GeoJsonGeometry` have finally been merged into a single enum (which was previously not done due to Objective-C support)
- This guarantees that invalid coordinate structure for a geometry type is unrepresentable
- We also use CLLocationCoordinate2D instead of keeping Double arrays

Since GDASpatialDataResultEntity objects (among others) are cached in the local Realm database, the schema is left unchanged, despite otherwise improving the usage
- Eventually, a migration from the legacy Obj-C Realm mode to the new Swift mode should be done, which will also allow objects to be stored more naturally.

I would also like to note that the various implementations of GeoJson objects do not entirely adhere to the spec, and it may be preferable to parse GeoJson objects while adhering to spec, and only then convert it into the desired forms.
This improves consistency with naming of GeoJsonGeometry and GeoJsonFeature, as well as reducing clutter.
This reduces the complexity significantly, and since they were already being called with callbacks, it doesn't change the end use as we can now just spawn a task

- HTTPStatusCode had inconsistent implementation between `nil` and `.unknown` for other status codes, so we now favor `.unknown`
Slowly moving up the call stack. This makes the process for queueing tile fetches much simpler, both via async and separating responsibilities
Switched to the newer RealmSwift, instead of the older Objective-C based version
Mostly this is a drop-in replacement due to backwards compatibility

Then updated definitions to the newer `@Persisted` syntax
Data cacheing documentation was very outdated, so updated that
Fixed some warnings
Split `SpatialDataCache` to only deal with our primary cached map data, moving the markers and route database handling to `SpatialDataCustom`
All modifications to the cache realm should be run on this actor to avoid race conditions

- Additionally, moved cache-related functions from SpatialDataContext to SpatialDataCache
- Clean up split predicates
Since the initializer will always set SuperCategories, it doesn't have to be optional

Also, added a retry version for getTileData
@2kai2kai2 2kai2kai2 mentioned this pull request Dec 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant