Skip to content

Commit

Permalink
perf: Speed up parsing of a huge query with a lot of conditional muta…
Browse files Browse the repository at this point in the history
…tions (#7871)
  • Loading branch information
Phill240 authored Sep 23, 2021
1 parent 3950c8f commit 3103f0e
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions edgraph/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -875,7 +875,10 @@ func buildUpsertQuery(qc *queryContext) string {
}

qc.condVars = make([]string, len(qc.req.Mutations))
upsertQuery := strings.TrimSuffix(qc.req.Query, "}")

var b strings.Builder
x.Check2(b.WriteString(strings.TrimSuffix(qc.req.Query, "}")))

for i, gmu := range qc.gmuList {
isCondUpsert := strings.TrimSpace(gmu.Cond) != ""
if isCondUpsert {
Expand All @@ -900,13 +903,13 @@ func buildUpsertQuery(qc *queryContext) string {
// The variable __dgraph_0__ will -
// * be empty if the condition is true
// * have 1 UID (the 0 UID) if the condition is false
upsertQuery += qc.condVars[i] + ` as var(func: uid(0)) ` + cond + `
`
x.Check2(b.WriteString(qc.condVars[i] + ` as var(func: uid(0)) ` + cond + `
`))
}
}
upsertQuery += `}`
x.Check2(b.WriteString(`}`))

return upsertQuery
return b.String()
}

// updateMutations updates the mutation and replaces uid(var) and val(var) with
Expand Down

0 comments on commit 3103f0e

Please sign in to comment.