Skip to content

Commit

Permalink
opt(GraphQL): filter existence queries on GraphQL side instead of using
Browse files Browse the repository at this point in the history
@filter(type) (#7757)

For the existence queries we used to do:
 query {\n  Cuisine_1(func: eq(Cuisine.name, \"yaMqnmHeov\")) @filter(type(Cuisine)) {\n uid \n  } \n}

The filter operation can be very heavy on dgraph.type as it may store millions of nodes. A better query could be like this:
 query {\n  Cuisine_1(func: eq(Cuisine.name, \"yaMqnmHeov\")) {\n uid dgraph.type \n  } \n}

This PR removes the above @filter operation from the existence query and uses the suggested alternate query which is lightweight.
The existence check operation is path critical and this fix is expected to add some performance improvement along with preventing OOM.
  • Loading branch information
NamanJain8 authored Apr 28, 2021
1 parent aff03e5 commit 690fbbe
Show file tree
Hide file tree
Showing 14 changed files with 590 additions and 326 deletions.
2 changes: 1 addition & 1 deletion graphql/admin/add_group.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ func NewAddGroupRewriter() resolve.MutationRewriter {
// AddRewriter.
func (mrw *addGroupRewriter) RewriteQueries(
ctx context.Context,
m schema.Mutation) ([]*gql.GraphQuery, error) {
m schema.Mutation) ([]*gql.GraphQuery, []string, error) {

return ((*resolve.AddRewriter)(mrw)).RewriteQueries(ctx, m)
}
Expand Down
4 changes: 2 additions & 2 deletions graphql/admin/update_group.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@ func NewUpdateGroupRewriter() resolve.MutationRewriter {
// nodes. It does not rewrite any queries.
func (urw *updateGroupRewriter) RewriteQueries(
ctx context.Context,
m schema.Mutation) ([]*gql.GraphQuery, error) {
m schema.Mutation) ([]*gql.GraphQuery, []string, error) {

urw.VarGen = resolve.NewVariableGenerator()
urw.XidMetadata = resolve.NewXidMetadata()

return []*gql.GraphQuery{}, nil
return []*gql.GraphQuery{}, []string{}, nil
}

// Rewrite rewrites set and remove update patches into dql upsert mutations
Expand Down
4 changes: 2 additions & 2 deletions graphql/e2e/common/mutation.go
Original file line number Diff line number Diff line change
Expand Up @@ -2933,7 +2933,7 @@ func addMultipleMutationWithOneError(t *testing.T) {
newAuth := addAuthor(t, newCountry.ID, postExecutor)

badAuth := &author{
ID: "0x0",
ID: "0x1234321", // A random non-existing ID
}

goodPost := &post{
Expand Down Expand Up @@ -3003,7 +3003,7 @@ func addMultipleMutationWithOneError(t *testing.T) {
require.NoError(t, err)

require.Contains(t, gqlResponse.Errors[0].Error(),
`because ID "0x0" isn't a Author`)
`because ID "0x1234321" isn't a Author`)

cleanUp(t, []*country{newCountry}, []*author{newAuth}, result.AddPost.Post)
}
Expand Down
Loading

0 comments on commit 690fbbe

Please sign in to comment.