Skip to content

Commit

Permalink
Eliminate use of 'null' in TaskReviewRepository query and improve rea…
Browse files Browse the repository at this point in the history
…dability
  • Loading branch information
ljdelight committed Aug 10, 2023
1 parent 44dd967 commit 89d5e5e
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 25 deletions.
24 changes: 15 additions & 9 deletions app/org/maproulette/framework/mixins/TaskParserMixin.scala
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ trait TaskParserMixin {
Option[String]
)
): RowParser[TaskWithReview] = {
// tasks fields
get[Long]("tasks.id") ~
get[String]("tasks.name") ~
get[DateTime]("tasks.created") ~
Expand All @@ -127,6 +128,12 @@ trait TaskParserMixin {
get[Option[DateTime]]("tasks.mapped_on") ~
get[Option[Long]]("tasks.completed_time_spent") ~
get[Option[Long]]("tasks.completed_by") ~
get[Int]("tasks.priority") ~
get[Option[Long]]("tasks.changeset_id") ~
get[Option[Long]]("tasks.bundle_id") ~
get[Option[Boolean]]("tasks.is_bundle_primary") ~
get[Option[String]]("responses") ~
// task_review fields
get[Option[Int]]("task_review.review_status") ~
get[Option[Long]]("task_review.review_requested_by") ~
get[Option[Long]]("task_review.reviewed_by") ~
Expand All @@ -139,21 +146,20 @@ trait TaskParserMixin {
get[Option[DateTime]]("task_review.review_claimed_at") ~
get[Option[List[Long]]]("task_review.additional_reviewers") ~
get[Option[String]]("task_review.error_tags") ~
get[Int]("tasks.priority") ~
get[Option[Long]]("tasks.changeset_id") ~
get[Option[Long]]("tasks.bundle_id") ~
get[Option[Boolean]]("tasks.is_bundle_primary") ~
// challenges and projects fields
get[Option[String]]("challenge_name") ~
get[Option[String]]("project_name") ~
// users fields
get[Option[String]]("review_requested_by_username") ~
get[Option[String]]("reviewed_by_username") ~
get[Option[String]]("responses") map {
get[Option[String]]("reviewed_by_username") map {
case id ~ name ~ created ~ modified ~ parent_id ~ instruction ~ location ~ status ~ geojson ~
cooperativeWork ~ mappedOn ~ completedTimeSpent ~ completedBy ~ reviewStatus ~ reviewRequestedBy ~
cooperativeWork ~ mappedOn ~ completedTimeSpent ~ completedBy ~
priority ~ changesetId ~ bundleId ~ isBundlePrimary ~ responses ~
reviewStatus ~ reviewRequestedBy ~
reviewedBy ~ reviewedAt ~ metaReviewedBy ~ metaReviewStatus ~ metaReviewedAt ~ reviewStartedAt ~
reviewClaimedBy ~ reviewClaimedAt ~ additionalReviewers ~ errorTags ~
priority ~ changesetId ~ bundleId ~ isBundlePrimary ~ challengeName ~ projectName ~
reviewRequestedByUsername ~ reviewedByUsername ~ responses =>
challengeName ~ projectName ~
reviewRequestedByUsername ~ reviewedByUsername =>
val values = updateAndRetrieve(id, geojson, location, cooperativeWork)
TaskWithReview(
Task(
Expand Down
44 changes: 28 additions & 16 deletions app/org/maproulette/framework/repository/TaskReviewRepository.scala
Original file line number Diff line number Diff line change
Expand Up @@ -480,19 +480,27 @@ class TaskReviewRepository @Inject() (
.build(
s"""
SELECT
-- tasks fields
tasks.id,
tasks.name,
tasks.created,
tasks.modified,
tasks.parent_id,
tasks.instruction,
NULL AS geo_location,
ST_AsGeoJSON(tasks.location) AS geo_location,
tasks.status,
NULL AS geo_json,
NULL AS cooperative_work,
tasks.geojson::TEXT AS geo_json,
tasks.cooperative_work_json::TEXT AS cooperative_work,
tasks.mapped_on,
tasks.completed_time_spent,
tasks.completed_by,
tasks.priority,
tasks.changeset_id,
tasks.bundle_id,
tasks.is_bundle_primary,
tasks.completion_responses::TEXT AS responses,

-- task_review fields
task_review.review_status,
task_review.review_requested_by,
task_review.reviewed_by,
Expand All @@ -505,22 +513,26 @@ class TaskReviewRepository @Inject() (
task_review.review_claimed_at,
task_review.additional_reviewers,
task_review.error_tags,
tasks.priority,
tasks.changeset_id,
tasks.bundle_id,
tasks.is_bundle_primary,

-- challenges and projects fields
c.name AS challenge_name,
p.display_name AS project_name,

-- users fields
mappers.name AS review_requested_by_username,
reviewers.name AS reviewed_by_username,
NULL AS responses
FROM
tasks
INNER JOIN task_review ON task_review.task_id = tasks.id
LEFT OUTER JOIN users mappers ON task_review.review_requested_by = mappers.id
LEFT OUTER JOIN users reviewers ON task_review.reviewed_by = reviewers.id
INNER JOIN challenges c ON c.id = tasks.parent_id
INNER JOIN projects p ON p.id = c.parent_id
reviewers.name AS reviewed_by_username

FROM tasks
-- Joining with task_review
INNER JOIN task_review ON task_review.task_id = tasks.id

-- Joining with challenges and projects
INNER JOIN challenges c ON c.id = tasks.parent_id
INNER JOIN projects p ON p.id = c.parent_id

-- Joining with users
LEFT OUTER JOIN users mappers ON task_review.review_requested_by = mappers.id
LEFT OUTER JOIN users reviewers ON task_review.reviewed_by = reviewers.id
"""
)
.as(reviewParser.*)
Expand Down

0 comments on commit 89d5e5e

Please sign in to comment.