refactor: (vertex, queryParam) -> edgeQueryParam
Project: http://git-wip-us.apache.org/repos/asf/incubator-s2graph/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-s2graph/commit/d7a630d4 Tree: http://git-wip-us.apache.org/repos/asf/incubator-s2graph/tree/d7a630d4 Diff: http://git-wip-us.apache.org/repos/asf/incubator-s2graph/diff/d7a630d4 Branch: refs/heads/master Commit: d7a630d418d9fb4468197f97d8ec5346b63cc5f3 Parents: 8ed6d20 Author: daewon <[email protected]> Authored: Fri Apr 20 15:59:18 2018 +0900 Committer: daewon <[email protected]> Committed: Fri Apr 20 15:59:23 2018 +0900 ---------------------------------------------------------------------- .../graphql/repository/GraphRepository.scala | 26 +++++++++----------- .../s2graph/graphql/types/FieldResolver.scala | 5 ++-- .../apache/s2graph/graphql/types/S2Type.scala | 13 ++++------ 3 files changed, 20 insertions(+), 24 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-s2graph/blob/d7a630d4/s2graphql/src/main/scala/org/apache/s2graph/graphql/repository/GraphRepository.scala ---------------------------------------------------------------------- diff --git a/s2graphql/src/main/scala/org/apache/s2graph/graphql/repository/GraphRepository.scala b/s2graphql/src/main/scala/org/apache/s2graph/graphql/repository/GraphRepository.scala index e5a04b1..3bfa556 100644 --- a/s2graphql/src/main/scala/org/apache/s2graph/graphql/repository/GraphRepository.scala +++ b/s2graphql/src/main/scala/org/apache/s2graph/graphql/repository/GraphRepository.scala @@ -40,8 +40,8 @@ object GraphRepository { override def id(value: (VertexQueryParam, Seq[S2VertexLike])): VertexQueryParam = value._1 } - implicit val edgeHasId = new HasId[(S2VertexLike, QueryParam, Seq[S2EdgeLike]), DeferFetchEdges] { - override def id(value: (S2VertexLike, QueryParam, Seq[S2EdgeLike])): DeferFetchEdges = DeferFetchEdges(value._1, value._2) + implicit val edgeHasId = new HasId[(EdgeQueryParam, Seq[S2EdgeLike]), EdgeQueryParam] { + override def id(value: (EdgeQueryParam, Seq[S2EdgeLike])): EdgeQueryParam = value._1 } val vertexFetcher = @@ -51,19 +51,20 @@ object GraphRepository { Future.traverse(queryParams)(ctx.getVertices).map(vs => queryParams.zip(vs)) }) - val edgeFetcher = Fetcher((ctx: GraphRepository, ids: Seq[DeferFetchEdges]) => { + val edgeFetcher = Fetcher((ctx: GraphRepository, edgeQueryParams: Seq[EdgeQueryParam]) => { implicit val ec = ctx.ec - val edgesByParam = ids.groupBy(_.qp).map { case (qp, deLs) => - val vertices = deLs.map(de => de.v) - - ctx.getEdges(vertices, qp).map(qp -> _) + val edgesByParam = edgeQueryParams.groupBy(_.qp).toSeq.map { case (qp, edgeQueryParams) => + val vertices = edgeQueryParams.map(_.v) + ctx.getEdges(vertices, qp).map(edges => qp -> edges) } - val f: Future[Iterable[(QueryParam, Seq[S2EdgeLike])]] = Future.sequence(edgesByParam) - val grouped: Future[Seq[(S2VertexLike, QueryParam, Seq[S2EdgeLike])]] = f.map { tpLs => - tpLs.toSeq.flatMap { case (qp, edges) => - edges.groupBy(_.srcForVertex).map { case (v, edges) => (v, qp, edges) } + val f: Future[Seq[(QueryParam, Seq[S2EdgeLike])]] = Future.sequence(edgesByParam) + val grouped: Future[Seq[(EdgeQueryParam, Seq[S2EdgeLike])]] = f.map { tpLs => + tpLs.flatMap { case (qp, edges) => + edges.groupBy(_.srcForVertex).map { + case (v, edges) => EdgeQueryParam(v, qp) -> edges + } } } @@ -78,9 +79,6 @@ object GraphRepository { tryObj } - - case class DeferFetchEdges(v: S2VertexLike, qp: QueryParam) - } class GraphRepository(val graph: S2GraphLike) { http://git-wip-us.apache.org/repos/asf/incubator-s2graph/blob/d7a630d4/s2graphql/src/main/scala/org/apache/s2graph/graphql/types/FieldResolver.scala ---------------------------------------------------------------------- diff --git a/s2graphql/src/main/scala/org/apache/s2graph/graphql/types/FieldResolver.scala b/s2graphql/src/main/scala/org/apache/s2graph/graphql/types/FieldResolver.scala index 1625f58..4423dc8 100644 --- a/s2graphql/src/main/scala/org/apache/s2graph/graphql/types/FieldResolver.scala +++ b/s2graphql/src/main/scala/org/apache/s2graph/graphql/types/FieldResolver.scala @@ -4,6 +4,7 @@ import org.apache.s2graph.core._ import org.apache.s2graph.core.mysqls._ import org.apache.s2graph.graphql.bind.AstHelper import org.apache.s2graph.graphql.repository.GraphRepository +import org.apache.s2graph.graphql.types.S2Type.EdgeQueryParam import sangria.schema._ object FieldResolver { @@ -28,7 +29,7 @@ object FieldResolver { } } - def label(label: Label, c: Context[GraphRepository, Any]): (S2VertexLike, QueryParam) = { + def label(label: Label, c: Context[GraphRepository, Any]): EdgeQueryParam = { val vertex = c.value.asInstanceOf[S2VertexLike] val dir = c.arg[String]("direction") @@ -46,7 +47,7 @@ object FieldResolver { where = where ) - (vertex, qp) + EdgeQueryParam(vertex, qp) } def serviceColumnOnService(column: ServiceColumn, c: Context[GraphRepository, Any]): VertexQueryParam = { http://git-wip-us.apache.org/repos/asf/incubator-s2graph/blob/d7a630d4/s2graphql/src/main/scala/org/apache/s2graph/graphql/types/S2Type.scala ---------------------------------------------------------------------- diff --git a/s2graphql/src/main/scala/org/apache/s2graph/graphql/types/S2Type.scala b/s2graphql/src/main/scala/org/apache/s2graph/graphql/types/S2Type.scala index c189fe3..c10d85e 100644 --- a/s2graphql/src/main/scala/org/apache/s2graph/graphql/types/S2Type.scala +++ b/s2graphql/src/main/scala/org/apache/s2graph/graphql/types/S2Type.scala @@ -19,22 +19,20 @@ package org.apache.s2graph.graphql.types -import scala.concurrent._ -import org.apache.s2graph.core.Management.JsonModel.{Index, Prop} +import org.apache.s2graph.core.Management.JsonModel._ import org.apache.s2graph.core._ import org.apache.s2graph.core.mysqls._ import org.apache.s2graph.graphql import org.apache.s2graph.graphql.repository.GraphRepository import sangria.schema._ -import org.apache.s2graph.graphql.bind.AstHelper -import org.apache.s2graph.graphql.repository -import org.apache.s2graph.graphql.repository.GraphRepository.DeferFetchEdges import org.apache.s2graph.graphql.types.StaticTypes._ import scala.language.existentials object S2Type { + case class EdgeQueryParam(v: S2VertexLike, qp: QueryParam) + case class AddVertexParam(timestamp: Long, id: Any, columnName: String, @@ -215,11 +213,10 @@ object S2Type { resolve = { c => implicit val ec = c.ctx.ec - val (vertex, queryParam) = graphql.types.FieldResolver.label(label, c) - val de = DeferFetchEdges(vertex, queryParam) + val edgeQueryParam = graphql.types.FieldResolver.label(label, c) val empty = Seq.empty[S2EdgeLike] - DeferredValue(GraphRepository.edgeFetcher.deferOpt(de)).map(m => m.fold(empty)(_._3)) + DeferredValue(GraphRepository.edgeFetcher.deferOpt(edgeQueryParam)).map(m => m.fold(empty)(_._2)) } )
