Developer forum

Forum » CMS - Standard features » Updating GeoLocation firing too often

Updating GeoLocation firing too often

Imar Spaanjaars Dynamicweb Employee
Imar Spaanjaars
Reply

Hi there,

Possibly related to TFS #65614 "Bug in Users code causes excessive (and expensive) calls to google api", we ran into an issue with Live Integration for users being really slow. We were able to relate this to Dynamicweb.Admin reaching out to Google to update a user's address. Here's the sequence of events:

1. A user updates an address in the Customer Center
2. Our Live Integration picks up the change and syncs the user with the ERP. In our code, we also call User.Save()
3. Calling User.Save() triggers the UserOnBeforeSave notification
4. That notification is picked up by Dynamicweb.Admin.Maps.UserNotificationSubscriber which then tries to update the Geo location by calling Google. It's here where the delays occur.

I think the code in there could be improved a bit by updating the user's GeoLocationHashCode even when there's no valid address. It currently looks like this:

public static GeoLocationStatus SetGeolocationFromGoogleMaps(User user, bool force = false)
{
    if (!force && user.IsGeolocationCustom)
    {
        return GeoLocationStatus.IsCustom;
    }
    string getLocationAddress = Maps.GetGetLocationAddress(user, " ");
    if (string.IsNullOrEmpty(getLocationAddress))
    {
        return GeoLocationStatus.NoAddress;
    }
    string geoLocationHash = Maps.GetGeoLocationHash(getLocationAddress);
    if (!force && geoLocationHash == user.GeolocationHashCode)
    {
        return GeoLocationStatus.NotChanged;
    }
    GeoLocation location = Maps.GetLocation(getLocationAddress);
    if (location == null)
    {
        return GeoLocationStatus.None;
    }
    user.GeolocationLatitude = location.Latitude;
    user.GeolocationLongitude = location.Longitude;
    user.GeolocationHashCode = geoLocationHash;
    return GeoLocationStatus.Updated;
}

I think that by updating the GeolocationHashCode even when no address is returned would fix the issue:

    GeoLocation location = Maps.GetLocation(getLocationAddress);
    if (location == null)
    {
      user.GeolocationHashCode = geoLocationHash;
      return GeoLocationStatus.None;
    }

That way, when a user has a faulty address that cannot be mapped, the hash is updated anyway and on the next save, no further attempt is made to update the address.

That still leaves the issue for when Google cannot be reached successfully (I think that's what's happening in our case; Google now requires an API key and we don't have one on our site). Would it make sense now that the key is required to update SetGeolocationFromGoogleMaps or Maps.GetLocation to not do anything when there is no key? Or otherwise add a checkbox in settings to disable the behavior altogether?

Thanks!

Imar


Replies

 
Imar Spaanjaars Dynamicweb Employee
Imar Spaanjaars
Reply

Bump. Any takers?

 
Vladimir Shushunov Dynamicweb Employee
Vladimir Shushunov
Reply

Hi Imar,

I'm not sure that updating the GeolocationHashCode when no address is returned is a good solution - there could be then a problem to update hash after any connection failures.

However it is really not right to make a request without a key - I will register a bug to fix this issue.

Best regards,
Vladimir

 
Imar Spaanjaars Dynamicweb Employee
Imar Spaanjaars
Reply

Makes sense, thanks!

 
Kristian Kirkholt Dynamicweb Employee
Kristian Kirkholt
Reply

Hi Imar

The problem regarding GeoLocation has now been resolved in Dynamicweb version 9.6.13 and 9.7+ version

To upgrade please choose this version from download:

http://doc.dynamicweb.com/releases-and-downloads/releases

Let me know if you need any more help regarding this

Kind Regards
Dynamicweb Support
Kristian Kirkholt

 

You must be logged in to post in the forum