Skip to content

Commit

Permalink
opt(schema): Optimize populateSchema() by avoiding repeated lock acqu…
Browse files Browse the repository at this point in the history
…isition (#8068) (#8071)

Optimize populateSchema() by avoiding repeated lock acquisition.
we can get the schema for the predicate once and then check for
the required field without taking a read lock.

(cherry picked from commit d935b8b)

Co-authored-by: Ahsan Barkati <[email protected]>
  • Loading branch information
NamanJain8 and ahsanbarkati authored Oct 5, 2021
1 parent 04ee066 commit 721d7d9
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions worker/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,28 +90,30 @@ func populateSchema(attr string, fields []string) *pb.SchemaNode {
}
schemaNode.Predicate = attr
ctx := context.Background()
pred, _ := schema.State().Get(ctx, attr)

for _, field := range fields {
switch field {
case "type":
schemaNode.Type = typ.Name()
case "index":
schemaNode.Index = schema.State().IsIndexed(ctx, attr)
schemaNode.Index = len(pred.GetTokenizer()) > 0
case "tokenizer":
if schema.State().IsIndexed(ctx, attr) {
if len(pred.GetTokenizer()) > 0 {
schemaNode.Tokenizer = schema.State().TokenizerNames(ctx, attr)
}
case "reverse":
schemaNode.Reverse = schema.State().IsReversed(ctx, attr)
schemaNode.Reverse = pred.GetDirective() == pb.SchemaUpdate_REVERSE
case "count":
schemaNode.Count = schema.State().HasCount(ctx, attr)
schemaNode.Count = pred.GetCount()
case "list":
schemaNode.List = schema.State().IsList(attr)
schemaNode.List = pred.GetList()
case "upsert":
schemaNode.Upsert = schema.State().HasUpsert(attr)
schemaNode.Upsert = pred.GetUpsert()
case "lang":
schemaNode.Lang = schema.State().HasLang(attr)
schemaNode.Lang = pred.GetLang()
case "noconflict":
schemaNode.NoConflict = schema.State().HasNoConflict(attr)
schemaNode.NoConflict = pred.GetNoConflict()
default:
//pass
}
Expand Down

0 comments on commit 721d7d9

Please sign in to comment.