diff --git a/app/org/maproulette/framework/service/LeaderboardService.scala b/app/org/maproulette/framework/service/LeaderboardService.scala index 10c4d183..7b98e41d 100644 --- a/app/org/maproulette/framework/service/LeaderboardService.scala +++ b/app/org/maproulette/framework/service/LeaderboardService.scala @@ -8,7 +8,7 @@ package org.maproulette.framework.service import javax.inject.{Inject, Singleton} import org.joda.time.DateTime import org.maproulette.Config -import org.maproulette.exception.NotFoundException +import org.maproulette.exception.{InvalidException, NotFoundException} import org.maproulette.framework.model.{LeaderboardChallenge, LeaderboardUser, Task, User} import org.maproulette.framework.mixins.LeaderboardMixin import org.maproulette.framework.repository.{ChallengeRepository, LeaderboardRepository} @@ -151,11 +151,20 @@ class LeaderboardService @Inject() ( fetchedUserId => this.getUserTopChallenges(fetchedUserId, params) ) - if (result.length > 0) { - return result - } + // NOTE: The result may be an empty list for users who are not in the leaderboard. + return result } + // The provided arguments are invalid because the combination cannot query from the pre-built table, throw an error (http 400). + throw new InvalidException( + "Dynamic queries are disabled. Adjust query parameters for static results." + ) + + // + // TODO(ljdelight): The below needs to be moved to a new endpoint because it CAN CRASH THE SERVER. We MUST always + // know whether the leaderboard is coming from a pre-built table or not. THUS SEPARATE ENDPOINTS. + // + val (startDate, endDate) = this.setupDates(params.monthDuration, params.start, params.end) val query = this @@ -220,11 +229,20 @@ class LeaderboardService @Inject() ( fetchedUserId => this.getUserTopChallenges(fetchedUserId, params) ) - if (result.length > 0) { - return result - } + // NOTE: The result may be an empty list for users who are not in the leaderboard. + return result } + // The provided arguments are invalid because the combination cannot query from the pre-built table, throw an error (http 400). + throw new InvalidException( + "Dynamic queries are disabled. Adjust query parameters for static results." + ) + + // + // TODO(ljdelight): The below needs to be moved to a new endpoint because it CAN CRASH THE SERVER. We MUST always + // know whether the leaderboard is coming from a pre-built table or not. THUS SEPARATE ENDPOINTS. + // + val (startDate, endDate) = this.setupDates(params.monthDuration, params.start, params.end) val rankQuery = this.leaderboardWithRankSQL( @@ -294,11 +312,20 @@ class LeaderboardService @Inject() ( ) ) - if (result.length > 0) { - return result - } + // NOTE: The result may be an empty list for users who are not in the leaderboard. + return result } + // The provided arguments are invalid because the combination cannot query from the pre-built table, throw an error (http 400). + throw new InvalidException( + "Dynamic queries are disabled. Adjust query parameters for static results." + ) + + // + // TODO(ljdelight): The below needs to be moved to a new endpoint because it CAN CRASH THE SERVER. We MUST always + // know whether the leaderboard is coming from a pre-built table or not. THUS SEPARATE ENDPOINTS. + // + val (startDate, endDate) = setupDates(params.monthDuration, params.start, params.end) val (boundingSearch, taskTableIfNeeded) = setupBoundingSearch(params.countryCodeFilter) diff --git a/test/org/maproulette/framework/service/LeaderboardServiceSpec.scala b/test/org/maproulette/framework/service/LeaderboardServiceSpec.scala index 6ea25778..e53c5fdd 100644 --- a/test/org/maproulette/framework/service/LeaderboardServiceSpec.scala +++ b/test/org/maproulette/framework/service/LeaderboardServiceSpec.scala @@ -30,8 +30,10 @@ class LeaderboardServiceSpec(implicit val application: Application) extends Fram var challenge: Challenge = null "LeaderboardService" should { - "get mapper leaderboard" taggedAs (LeaderboardTag) in { - val params = SearchLeaderboardParameters(onlyEnabled = false) + // TODO(ljdelight): Temporarily ignored due to the disabling of dynamic leaderboard queries to improve system stability. + // This test will be revisited once an alternative approach or solution is implemented. + "get mapper leaderboard" taggedAs (LeaderboardTag) ignore { + val params = SearchLeaderboardParameters(onlyEnabled = true) val results = this.service.getMapperLeaderboard(params) results.size mustEqual 2 @@ -85,13 +87,17 @@ class LeaderboardServiceSpec(implicit val application: Application) extends Fram ccResults.size mustEqual 2 } - "get leaderboard for user" taggedAs (LeaderboardTag) in { + // TODO(ljdelight): Temporarily ignored due to the disabling of dynamic leaderboard queries to improve system stability. + // This test will be revisited once an alternative approach or solution is implemented. + "get leaderboard for user" taggedAs (LeaderboardTag) ignore { val results = this.service.getLeaderboardForUser(randomUser.id, SearchLeaderboardParameters()) results.size mustEqual 1 results.head.userId mustEqual randomUser.id } - "get leaderboard for user with bracketing" taggedAs (LeaderboardTag) in { + // TODO(ljdelight): Temporarily ignored due to the disabling of dynamic leaderboard queries to improve system stability. + // This test will be revisited once an alternative approach or solution is implemented. + "get leaderboard for user with bracketing" taggedAs (LeaderboardTag) ignore { val results = this.service .getLeaderboardForUser(randomUser.id, SearchLeaderboardParameters(), bracket = 1) results.size mustEqual 2