Skip to content

Commit

Permalink
apply miles's fix to plannedTimeHandler
Browse files Browse the repository at this point in the history
  • Loading branch information
tpolecat committed Sep 12, 2023
1 parent 760a51c commit 69ba7d7
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import lucuma.odb.graphql.table.GroupElementView
import lucuma.odb.logic.PlannedTimeCalculator
import lucuma.odb.sequence.util.CommitHash
import lucuma.odb.service.Services
import edu.gemini.grackle.syntax.*

import Services.Syntax.*
import binding._
Expand Down Expand Up @@ -150,20 +151,24 @@ trait ProgramMapping[F[_]]
def runEffects(queries: List[(Query, Cursor)]): F[Result[List[(Query, Cursor)]]] =
(for {
ctx <- ResultT(queries.traverse { case (_, cursor) => cursor.fieldAs[Program.Id]("id") }.pure[F])
res <- ctx.distinct.traverse { pid => ResultT(calculate(pid).map(Result.success)).tupleLeft(pid) }
} yield
ctx
.flatMap(pid => res.find(r => r._1 === pid).map(_._2).toList)
.zip(queries)
.map { case (result, (child, parentCursor)) =>
import lucuma.odb.json.plannedtime.given
import lucuma.odb.json.time.query.given
val json: Json = Json.fromFields(List("plannedTimeRange" -> result.asJson))
val cursor: Cursor = CirceCursor(parentCursor.context, json, Some(parentCursor), parentCursor.fullEnv)
(child, cursor)
}
ps <- ctx.distinct.traverse { pid => ResultT(calculate(pid).map(Result.success)).tupleLeft(pid) }
res <- ResultT(ctx
.flatMap(pid => ps.find(r => r._1 === pid).map(_._2).toList)
.zip(queries)
.traverse { case (result, (child, childCursor)) =>
import lucuma.odb.json.plannedtime.given
import lucuma.odb.json.time.query.given
childCursor.context.parent.toResultOrError("No parent context").map { parentContext =>
val parentField = childCursor.path.head
val json: Json = Json.fromFields(List(parentField -> Json.fromFields(List("plannedTimeRange" -> result.asJson))))
val cursor: Cursor = CirceCursor(parentContext, json, Some(childCursor), childCursor.fullEnv)
(Query.Select(parentField, None, child), cursor)
}
}.pure[F]
)
} yield res
).value
}

}
}

Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ class itc extends OdbSuite with ObservingModeSetupOperations {
case _ => sys.error("Expected two targets")
}

// RCN: succeeds if we don't select `id`
test("success, one target".ignore) {
setup1.flatMap { case (_, oid, tid) =>
expect(
Expand Down

0 comments on commit 69ba7d7

Please sign in to comment.