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

Inefficient Overpass queries #4

Closed
mmd-osm opened this issue Jul 23, 2017 · 10 comments
Closed

Inefficient Overpass queries #4

mmd-osm opened this issue Jul 23, 2017 · 10 comments

Comments

@mmd-osm
Copy link

mmd-osm commented Jul 23, 2017

I believe your library creates rather inefficient Overpass queries, which consume quite some resources on the server. Btw: it looks like this code originates from CyanogenMod/android_packages_apps_Dialer, is this correct? Do you know who is maintaining this?

https://github.com/AICP/packages_apps_Dialer/blob/n7.1/src/com/android/dialer/lookup/openstreetmap/OpenStreetMapForwardLookup.java#L53

Here are few recommendations on how you could improve the situation:

  • Replace (around: ) by a bounding box filter ({{bbox}}.
    This is much more efficient and causes less server load. This means that you would have to calculate a suitable bounding box on your own and use it in the query.

    Example:

    • [out:json];node[name~"[Xx][Ee]"][phone](around:30000,21.104282,105.978105);out body;

      => Takes 3s - 15s

    • [out:json];node[name~"[Xx][Ee]"][phone](20.86266160095456,105.66238403320312,21.193374899371197,106.0400390625);out body;
      => Just takes 1s

  • Enforce a minimum number of characters for name, no single character name queries, please.

  • Don't use the service in a type-ahead fashion, as this will quickly trigger HTTP 429 errors due to rate limiting.

  • Make sure, your users don't enter a phone number in the name field, because that really doesn't make that much sense. There are many queries like:
    [out:json];node[name~"[99][11][99][22][44]"][phone](around:30000,16.783533,82.077653);out body;

  • Cache requests on your end, don't repeatedly send the same requests

  • Always send a suitable HTTP User-Agent Header field

Thanks!

// cc: @chenxiaolong

@LorDClockaN
Copy link

It's a code from LineageOS

Thanks

@LorDClockaN
Copy link

Don't know who maintains it

@LorDClockaN
Copy link

@mmd-osm like this?
http://gerrit.aicp-rom.com/42394

@mmd-osm
Copy link
Author

mmd-osm commented Jul 23, 2017

Hi,

you need to pass an actual bounding box to the query, like described here: http://wiki.openstreetmap.org/wiki/Overpass_API/Overpass_QL#Bounding_box

  • or - like in the example I've mentioned above: (20.86266160095456,105.66238403320312,21.193374899371197,106.0400390625)

{{bbox}} was just a shortcut that you could use on overpass-turbo.eu - but as you're sending requests directly to overpass.api.de (the server backend), actual south,west,north,east values are really required.

This site has a good description of the approach and even a reference implementation in Java: http://janmatuschek.de/LatitudeLongitudeBoundingCoordinates

@LorDClockaN
Copy link

LorDClockaN commented Jul 23, 2017

I know shit about SQL

you can comment on the gerrit patch that I linked with actual code and please post your github user and email so I can put you as an author

@LorDClockaN
Copy link

I edited my post lol.. It looked like I told you that you don't know shit about sql hahaha

@mmd-osm
Copy link
Author

mmd-osm commented Jul 23, 2017

Sure, no problem.

It's a code from LineageOS

Coming to think about it, I should probably open an issue with LineageOS then. However, they seem to have a pretty strange bug reporting policy and need logcat attached, which I don't have for obvious reasons (see https://wiki.lineageos.org/bugreport-howto.html).

Oh, well. We might consider blocking these kind of queries altogether.

@mmd-osm mmd-osm closed this as completed Jul 23, 2017
@chenxiaolong
Copy link

...
// cc: @chenxiaolong

Sorry, due to my employment, I can't submit a patch for this without going through an approval process.

@mmd-osm
Copy link
Author

mmd-osm commented Jul 23, 2017

@chenxiaolong : thank you for your feedback! Could you point us to a location where we should report this issue, so that we can keep track of it?

@chenxiaolong
Copy link

@mmd-osm I'm not aware of a bug tracker for this kind of issue. It's been several years since I contributed to an Android ROM. At the time, I'm pretty sure I just submitted a pull request at CyanogenMod's (now LineageOS's) Gerrit instance. It wasn't attached to any feature request ticket or bug report.

Sorry I couldn't help more!

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

No branches or pull requests

3 participants