Skip to content
This repository has been archived by the owner on Sep 2, 2022. It is now read-only.

Commit

Permalink
Merge pull request #1448 from graphcool/ExportManyRelationsFix
Browse files Browse the repository at this point in the history
Export many relations fix
  • Loading branch information
do4gr authored Dec 22, 2017
2 parents df37652 + 26d01ca commit 499c85f
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ class ProjectDataresolver(override val project: Project, override val requestCon
.map(resultTransform(_))
}

//we could do this without validation to be faster
//also check whether the hasNext has made the overrideMaxNodeCount obsolete
def loadModelRowsForExport(model: Model, args: Option[QueryArguments] = None): Future[ResolverResult] = {
val (query, resultTransform) = DatabaseQueryBuilder.selectAllFromModel(project.id, model.name, args, overrideMaxNodeCount = Some(1001))

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class BulkExport(implicit clientInjector: ClientInjector) {
def executeExport(project: Project, dataResolver: DataResolver, json: JsValue): Future[JsValue] = {
val start = JsonBundle(Vector.empty, 0)
val request = json.convertTo[ExportRequest]
val hasListFields = project.models.flatMap(_.fields).exists(_.isList)
val hasListFields = project.models.flatMap(_.scalarListFields).nonEmpty
val zippedRelations = RelationInfo(dataResolver, project.relations.map(r => toRelationData(r, project)).zipWithIndex, request.cursor)
val zippedListModels = project.models.filter(m => m.scalarListFields.nonEmpty).zipWithIndex

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,18 +42,18 @@ package object ImportExport {
}

case class ListInfo(dataResolver: DataResolver, models: List[(Model, Int)], cursor: Cursor) extends ExportInfo {
val length: Int = models.length
val listFields: List[(String, TypeIdentifier, Int)] = currentModel.scalarListFields.zipWithIndex.map { case (f, i) => (f.name, f.typeIdentifier, i) }
val fieldLength: Int = listFields.length
val hasNext: Boolean = cursor.table < length - 1
val hasNextField: Boolean = cursor.field < fieldLength - 1
lazy val currentModel: Model = models.find(_._2 == cursor.table).get._1
lazy val nextModel: Model = models.find(_._2 == cursor.table + 1).get._1
lazy val currentField: String = listFields.find(_._3 == cursor.field).get._1
lazy val nextField: String = listFields.find(_._3 == cursor.field + 1).get._1
lazy val currentTypeIdentifier: TypeIdentifier = listFields.find(_._3 == cursor.field).get._2
def arrayPlus(increase: Int): ListInfo = this.copy(cursor = this.cursor.copy(array = this.cursor.array + increase))
def cursorAtNextField: ListInfo = this.copy(cursor = this.cursor.copy(field = this.cursor.field + 1, array = 0))
val length: Int = models.length
val hasNext: Boolean = cursor.table < length - 1
val hasNextField: Boolean = cursor.field < fieldLength - 1
lazy val currentModel: Model = models.find(_._2 == cursor.table).get._1
lazy val nextModel: Model = models.find(_._2 == cursor.table + 1).get._1
lazy val listFields: List[(String, TypeIdentifier, Int)] = currentModel.scalarListFields.zipWithIndex.map { case (f, i) => (f.name, f.typeIdentifier, i) }
lazy val fieldLength: Int = listFields.length
lazy val currentField: String = listFields.find(_._3 == cursor.field).get._1
lazy val nextField: String = listFields.find(_._3 == cursor.field + 1).get._1
lazy val currentTypeIdentifier: TypeIdentifier = listFields.find(_._3 == cursor.field).get._2
def arrayPlus(increase: Int): ListInfo = this.copy(cursor = this.cursor.copy(array = this.cursor.array + increase))
def cursorAtNextField: ListInfo = this.copy(cursor = this.cursor.copy(field = this.cursor.field + 1, array = 0))
}

case class RelationInfo(dataResolver: DataResolver, relations: List[(RelationData, Int)], cursor: Cursor) extends ExportInfo {
Expand Down

0 comments on commit 499c85f

Please sign in to comment.