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

Add location limit and bigger default radius value #48

Merged
merged 1 commit into from
May 29, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ public async Task<Guid[]> GetNearPartnerIdsAsync(double? radiusInKm, double? lon
throw new ArgumentException("Invalid argument value for get near partners request");

var searchByCoordinates = latitude.HasValue && longitude.HasValue;
radiusInKm = radiusInKm ?? 1;
radiusInKm = radiusInKm ?? 8;

var locations = searchByCoordinates
? await GetLocationsByCoordinates(latitude.Value, longitude.Value, radiusInKm.Value, iso3Code)
Expand All @@ -257,8 +257,9 @@ public async Task<Guid[]> GetNearPartnerIdsAsync(double? radiusInKm, double? lon
private async Task<IEnumerable<Location>> GetLocationsByCoordinates(double latitude, double longitude, double radiusInKm, string iso3Code)
{
string geohash = null;
var hasAnyLocations = false;
var locationsCount = 0;
IEnumerable<Location> locations = null;
const int locationsLimit = 20;
//Try to get locations in radius if there are not locations in this radius,
//increase it and try again until you find location or the radius exceeds the maximum allowed
do
Expand Down Expand Up @@ -287,10 +288,10 @@ private async Task<IEnumerable<Location>> GetLocationsByCoordinates(double latit
.OrderBy(l => locationDistances[l.Id]);
}

hasAnyLocations = locations.Any();
locationsCount = locations.Count();
radiusInKm *= 2;

} while (radiusInKm <= MaxRadiusInKm && !hasAnyLocations);
} while (radiusInKm <= MaxRadiusInKm && locationsCount < locationsLimit);

return locations;
}
Expand Down