Skip to content

Commit

Permalink
using expandBatchActionNew and removes old expandBatchAction
Browse files Browse the repository at this point in the history
  • Loading branch information
juliano committed Jul 29, 2023
1 parent a5fb2b1 commit 23da175
Showing 1 changed file with 12 additions and 29 deletions.
41 changes: 12 additions & 29 deletions quill-core/src/main/scala/io/getquill/context/ActionMacro.scala
Original file line number Diff line number Diff line change
Expand Up @@ -37,18 +37,25 @@ class ActionMacro(val c: MacroContext) extends ContextMacro with ReifyLiftings {
translateBatchQueryPrettyPrint(quoted, q"false")

def translateBatchQueryPrettyPrint(quoted: Tree, prettyPrint: Tree): Tree =
expandBatchAction(quoted) { case (batch, param, expanded) =>
q"""
expandBatchActionNew(quoted, false) {
case (batch, param, expanded, injectableLiftList, idiomNamingOriginalAstVars, idiomContext, canDoBatch) =>
q"""
..${EnableReflectiveCalls(c)}
val batches =
if ($canDoBatch) {
$batch.toList.grouped(1).toList
} else {
$batch.toList.map(element => List(element))
}
${c.prefix}.translateBatchQuery(
$batch.map { $param =>
val (idiomContext, expanded) = $expanded
batches.map { subBatch =>
val expanded = $expanded
(expanded.string, expanded.prepare)
}.groupBy(_._1).map {
case (string, items) =>
${c.prefix}.BatchGroup(string, items.map(_._2).toList)
}.toList,
${prettyPrint}
$prettyPrint
)(io.getquill.context.ExecutionInfo.unknown, ())
"""
}
Expand Down Expand Up @@ -333,30 +340,6 @@ class ActionMacro(val c: MacroContext) extends ContextMacro with ReifyLiftings {
})
"""

def expandBatchAction(quoted: Tree)(call: (Tree, Tree, Tree) => Tree): Tree =
BetaReduction(extractAst(quoted)) match {
case totalAst @ Foreach(lift: Lift, alias, body) =>
val batch = lift.value.asInstanceOf[Tree]
val batchItemType = batch.tpe.typeArgs.head
c.typecheck(q"(value: $batchItemType) => value") match {
case q"($param) => $value" =>
val nestedLift =
lift match {
case ScalarQueryLift(name, batch: Tree, encoder: Tree, quat) =>
ScalarValueLift("value", External.Source.UnparsedProperty("value"), value, encoder, quat)
case CaseClassQueryLift(name, batch: Tree, quat) =>
CaseClassValueLift("value", "value", value, quat)
}
val (ast, _) = reifyLiftings(BetaReduction(body, alias -> nestedLift))
val expanded = expand(ast, Quat.Unknown)
c.untypecheck {
call(batch, param, expanded)
}
}
case other =>
c.fail(s"Batch actions must be static quotations. Found: '$other'")
}

def prepareAction(quoted: Tree): Tree =
c.untypecheck {
q"""
Expand Down

0 comments on commit 23da175

Please sign in to comment.