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

Available old map tiles not used #4015

Closed
Helium314 opened this issue May 6, 2022 · 5 comments · Fixed by #4027
Closed

Available old map tiles not used #4015

Helium314 opened this issue May 6, 2022 · 5 comments · Fixed by #4027

Comments

@Helium314
Copy link
Collaborator

When map tiles are older than 14 days, the files will remain in the cache, but the tiles are not displayed.
This can lead to situations where map data is available, but there is no background map shown.

How to Reproduce

  1. Have a fresh install of StreetComplete
  2. Download two areas (manual or automatic doesn't matter)
  3. Wait a week
  4. Open StreetComplete and download one of the areas again
  5. Wait another week
  6. Disable internet connection
  7. Open StreetComplete and check both areas
  8. See that map and quests in the area only downloaded 2 weeks ago has disappeared (not totally surprising)
  9. See that map in the area downloaded 1 week ago has disappeared, but quests are still shown
  10. Check [internal storage]/Android/data/de.westnordost.streetcomplete/cache/tile_cache and see a bunch of 2 week old files

So it seems the tile cache prefers not showing tiles over showing "too old" tiles.
At the same time the old unused tiles are not deleted, and apparently just sitting around waiting until the cache reaches maximum size.

Suggestions for solution, in order of my personal preference:

  • Use available tiles if there is no internet connection (and download them again if there is connection)
  • Always download map tiles when downloading an area to have the same download time for both
  • Delete tiles after 14 days, as they aren't used for anything

Versions affected
StreetComplete 42.0 (F-Droid)

@Helium314 Helium314 added the bug label May 6, 2022
@Helium314
Copy link
Collaborator Author

I did not find a way of directly telling the cache to use all old tiles when offline, but (re-)download them if internet connection is available.
But it should be possible to have two different cacheControl, a normal one and one with very large maxStale to be used when offline.

@westnordost westnordost added enhancement help wanted help by contributors is appreciated; might be a good first contribution for first-timers and removed bug labels May 13, 2022
@westnordost
Copy link
Member

westnordost commented May 13, 2022

Hmm, as you know, the cache is managed by OkHttp. I am not sure if it allows such control over it.

Anyway, the way your suggestion could work is to let the MapFragment listen to connectivity changes and store the connectivity state (connected to internet or not) in a local boolean variable.
Then, in MapFragment.createHttpHandler in configureRequest, use the cache control with very large maxStale if not connected and otherwise the normal one.

But I'll not do this because I find this not so important to invest time in it. PR is welcome as long as the workaround remains relatively simple.

@westnordost westnordost removed the help wanted help by contributors is appreciated; might be a good first contribution for first-timers label May 13, 2022
@Helium314
Copy link
Collaborator Author

Ok, I got it working and more or less ready for PR, but I noticed that it would be possible to have different cacheControl for MapFragment (which I understand goes to Tangram for downloading tiles when scrolling) and MapTilesDownloader (which downloads tiles as part of the data data download).
I think it would be ok to always set longer maxStale in MapFragment, independent of connection, because old map tiles will be replaced when downloading data anyway, and without data the importance of having recent tiles is rather low.

@Helium314
Copy link
Collaborator Author

This alternative would also reduce problems with a bad internet connection (online, but tiles can't be downloaded)

@westnordost
Copy link
Member

Hmm, right

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants