Skip to content

Commit

Permalink
further simplify markers endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
CollinBeczak committed Jul 19, 2024
1 parent 2519f4a commit 8675458
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 45 deletions.
15 changes: 6 additions & 9 deletions app/org/maproulette/framework/controller/TaskController.scala
Original file line number Diff line number Diff line change
Expand Up @@ -139,25 +139,22 @@ class TaskController @Inject() (
top: Double,
limit: Int,
excludeLocked: Boolean,
includeGeometries: Boolean
includeGeometries: Boolean,
includeTags: Boolean
): Action[AnyContent] = Action.async { implicit request =>
this.sessionManager.userAwareRequest { implicit user =>
SearchParameters.withSearch { p =>
val params = p.copy(location = Some(SearchLocation(left, bottom, right, top)))
val (count, result) = this.taskClusterService.getTaskMarkerDataInBoundingBox(
val result = this.taskClusterService.getTaskMarkerDataInBoundingBox(
User.userOrMocked(user),
params,
limit,
excludeLocked
)

result match {
case Some(points) =>
val resultJson = this.insertExtraTaskJSON(points)
Ok(Json.obj("total" -> count, "tasks" -> resultJson))
case None =>
Ok(Json.obj("total" -> count))
}
val resultJson = this.insertExtraTaskJSON(result, includeGeometries, includeTags)

Ok(resultJson)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class TaskClusterRepository @Inject() (override val db: Database, challengeDAL:

val DEFAULT_NUMBER_OF_POINTS = 100

val pointParser = this.challengeDAL.pointParser
val pointParser = this.challengeDAL.pointParser

private val joinClause =
new StringBuilder(
Expand Down Expand Up @@ -182,40 +182,28 @@ class TaskClusterRepository @Inject() (override val db: Database, challengeDAL:
def queryTaskMarkerDataInBoundingBox(
query: Query,
limit: Int
): (Int, Option[List[ClusteredPoint]]) = {
): List[ClusteredPoint] = {
this.withMRTransaction { implicit c =>
val count =
query.build(s"""
SELECT count(*) FROM tasks
${joinClause.toString()}
""").as(SqlParser.int("count").single)

if (count < limit) {
val results =
query
.build(
s"""
SELECT tasks.id, tasks.name, tasks.parent_id, c.name, tasks.instruction, tasks.status, tasks.mapped_on,
tasks.completed_time_spent, tasks.completed_by,
tasks.bundle_id, tasks.is_bundle_primary, tasks.cooperative_work_json::TEXT as cooperative_work,
task_review.review_status, task_review.review_requested_by, task_review.reviewed_by, task_review.reviewed_at,
task_review.review_started_at, task_review.meta_review_status, task_review.meta_reviewed_by,
task_review.meta_reviewed_at, task_review.additional_reviewers,
ST_AsGeoJSON(tasks.location) AS location, priority,
CASE WHEN task_review.review_started_at IS NULL
THEN 0
ELSE EXTRACT(epoch FROM (task_review.reviewed_at - task_review.review_started_at)) END
AS reviewDuration
FROM tasks
${joinClause.toString()}
"""
)
.as(this.pointParser.*)

(count, Some(results))
} else {
(count, Option.empty[List[ClusteredPoint]])
}
val finalQuery = query.copy(finalClause = s"""LIMIT $limit""")
val results = finalQuery
.build(s"""
SELECT tasks.id, tasks.name, tasks.parent_id, c.name, tasks.instruction, tasks.status, tasks.mapped_on,
tasks.completed_time_spent, tasks.completed_by,
tasks.bundle_id, tasks.is_bundle_primary, tasks.cooperative_work_json::TEXT as cooperative_work,
task_review.review_status, task_review.review_requested_by, task_review.reviewed_by, task_review.reviewed_at,
task_review.review_started_at, task_review.meta_review_status, task_review.meta_reviewed_by,
task_review.meta_reviewed_at, task_review.additional_reviewers,
ST_AsGeoJSON(tasks.location) AS location, priority,
CASE WHEN task_review.review_started_at IS NULL
THEN 0
ELSE EXTRACT(epoch FROM (task_review.reviewed_at - task_review.review_started_at)) END
AS reviewDuration
FROM tasks
${joinClause.toString()}
""")
.as(this.pointParser.*)

results
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ class TaskClusterService @Inject() (repository: TaskClusterRepository)
params: SearchParameters,
limit: Int,
ignoreLocked: Boolean = false
): (Int, Option[List[ClusteredPoint]]) = {
): (List[ClusteredPoint]) = {
params.location match {
case Some(sl) => // params has location
case None =>
Expand Down
2 changes: 1 addition & 1 deletion conf/v2_route/task.api
Original file line number Diff line number Diff line change
Expand Up @@ -571,7 +571,7 @@ PUT /tasks/box/:left/:bottom/:right/:top @org.maproulette.framework.c
# in: query
# description: Optional flag to have geometries data returned for each task.
###
PUT /markers/box/:left/:bottom/:right/:top @org.maproulette.framework.controller.TaskController.getTaskMarkerDataInBoundingBox(left:Double, bottom:Double, right:Double, top:Double, limit:Int ?= 500, excludeLocked:Boolean ?= false, includeGeometries:Boolean ?= false)
PUT /markers/box/:left/:bottom/:right/:top @org.maproulette.framework.controller.TaskController.getTaskMarkerDataInBoundingBox(left:Double, bottom:Double, right:Double, top:Double, limit:Int ?= 500, excludeLocked:Boolean ?= false, includeGeometries:Boolean ?= false, includeTags:Boolean ?= false)
###
# tags: [ Task ]
# summary: Update Task Changeset
Expand Down

0 comments on commit 8675458

Please sign in to comment.