Repository: dgraph-io/dgraph
File: edgraph/server.go (Go)

Code before:
			m["name"] = field.Predicate
			fields[i] = m
		}
		typeMap["fields"] = fields

		res = append(res, typeMap)
	}
	return res
}

func isDropAll(op *api.Operation) bool {
	if op.DropAll || op.DropOp == api.Operation_ALL {
		return true
	}
	return false
}

func verifyUniqueWithinMutation(qc *queryContext) error {
	if len(qc.uniqueVars) == 0 {
		return nil
	}

	for i := range qc.uniqueVars {
		gmuIndex, rdfIndex := decodeIndex(i)
		// handles cases where the mutation was pruned in updateMutations
		if int(gmuIndex) >= len(qc.gmuList) || qc.gmuList[gmuIndex] == nil || int(rdfIndex) >= len(qc.gmuList[gmuIndex].Set) {
			continue
		}
		pred1 := qc.gmuList[gmuIndex].Set[rdfIndex]
		pred1Value := dql.TypeValFrom(pred1.ObjectValue).Value
		for j := range qc.uniqueVars {
			if i == j {
				continue
			}
			gmuIndex2, rdfIndex2 := decodeIndex(j)
			// bounds check for the second predicate, which could also have been pruned
			if int(gmuIndex2) >= len(qc.gmuList) || qc.gmuList[gmuIndex2] == nil || int(rdfIndex2) >= len(qc.gmuList[gmuIndex2].Set) {
				continue
			}
			pred2 := qc.gmuList[gmuIndex2].Set[rdfIndex2]
			if pred1.Predicate == pred2.Predicate && dql.TypeValFrom(pred2.ObjectValue).Value == pred1Value &&
				pred1.Subject != pred2.Subject {
				return errors.Errorf("could not insert duplicate value [%v] for predicate [%v]",
					pred1Value, pred1.Predicate)
			}
		}
	}
	return nil
}

func isUpsertCondTrue(qc *queryContext, gmuIndex int) bool {

Review comment (suggestion):
Avoid casting unsigned indices to `int` for bounds checks; prefer comparing the original `uint32` values directly (e.g., `gmuIndex >= uint32(len(qc.gmuList))`) to maintain type safety.
```suggestion
		if gmuIndex >= uint32(len(qc.gmuList)) || qc.gmuList[gmuIndex] == nil || rdfIndex >= uint32(len(qc.gmuList[gmuIndex].Set)) {
```

Code after:
			m["name"] = field.Predicate
			fields[i] = m
		}
		typeMap["fields"] = fields

		res = append(res, typeMap)
	}
	return res
}

func isDropAll(op *api.Operation) bool {
	if op.DropAll || op.DropOp == api.Operation_ALL {
		return true
	}
	return false
}

func verifyUniqueWithinMutation(qc *queryContext) error {
	if len(qc.uniqueVars) == 0 {
		return nil
	}

	for i := range qc.uniqueVars {
		gmuIndex, rdfIndex := decodeIndex(i)
		// handles cases where the mutation was pruned in updateMutations
		if gmuIndex >= uint32(len(qc.gmuList)) || qc.gmuList[gmuIndex] == nil || rdfIndex >= uint32(len(qc.gmuList[gmuIndex].Set)) {
			continue
		}
		pred1 := qc.gmuList[gmuIndex].Set[rdfIndex]
		pred1Value := dql.TypeValFrom(pred1.ObjectValue).Value
		for j := range qc.uniqueVars {
			if i == j {
				continue
			}
			gmuIndex2, rdfIndex2 := decodeIndex(j)
			// check for the second predicate, which could also have been pruned
			if gmuIndex2 >= uint32(len(qc.gmuList)) || qc.gmuList[gmuIndex2] == nil || rdfIndex2 >= uint32(len(qc.gmuList[gmuIndex2].Set)) {
				continue
			}
			pred2 := qc.gmuList[gmuIndex2].Set[rdfIndex2]
			if pred2.Predicate == pred1.Predicate && dql.TypeValFrom(pred2.ObjectValue).Value == pred1Value &&
				pred2.Subject != pred1.Subject {
				return errors.Errorf("could not insert duplicate value [%v] for predicate [%v]",
					pred1Value, pred1.Predicate)
			}
		}
	}
	return nil
}

func isUpsertCondTrue(qc *queryContext, gmuIndex int) bool {