Skip to content

Commit

Permalink
Restrict photo.giveNearestPhotos distance
Browse files Browse the repository at this point in the history
Since nearSpehre is costly on big distances, especially in low points
density areas, it is reasonable to make it 10km by default, It is used
in Nearest Photos feed in photo view which does not require very distant
photo to show for the price of slow Mongo response.  Method was also in
API use, we restrict max distance to 1000km for the same reason.
  • Loading branch information
kabalin committed Jan 23, 2022
1 parent 8ed6fab commit fba0865
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions controllers/photo.js
Original file line number Diff line number Diff line change
Expand Up @@ -1936,7 +1936,7 @@ async function giveUserPhotosAround({ cid, limitL, limitR }) {
* @param {number} obj.year
* @param {number} obj.year2
* @param {number} obj.except cid to exclude
* @param {number} obj.distance distance in radians
* @param {number} obj.distance distance in meters (1000km max)
* @param {number} obj.limit
* @param {number} obj.skip
* @returns {object[]} photos
Expand Down Expand Up @@ -1977,11 +1977,11 @@ async function giveNearestPhotos({ geo, type, year, year2, except, distance, lim
query.cid = { $ne: except };
}

if (_.isNumber(distance) && distance > 0 && distance < Math.PI) {
query.geo.$nearSphere.$maxDistance = Utils.geo.rad2meter(distance);
if (_.isNumber(distance) && distance > 0) {
query.geo.$nearSphere.$maxDistance = Math.min(1000000, distance);
} else {
// By default restrict distance to hemisphere with the center at the point.
query.geo.$nearSphere.$maxDistance = Utils.geo.rad2meter(Math.PI / 2);
// By default restrict distance to 10km.
query.geo.$nearSphere.$maxDistance = 10000;
}

if (_.isNumber(limit) && limit > 0 && limit < 30) {
Expand Down

0 comments on commit fba0865

Please sign in to comment.