Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,41 @@
import org.apache.tinkerpop.gremlin.structure.Vertex;

public abstract class AbstractStaticRule extends AbstractRule implements StaticRule {

@Override
public final List<Violation> run(GraphTraversalSource g) {
return run(g, new ArrayList<>());
}

/**
* TinkerGraph's .union() operator degrades non-linearly when given thousands of
* sub-traversals. Splitting targets into batches of this size keeps each .union()
* manageable and avoids the performance cliff.
*/
private static final int BATCH_SIZE = 500;

public final List<Violation> run(
GraphTraversalSource g, List<AbstractRuleRunner.RuleRunnerTarget> targets) {
GraphTraversal<Vertex, Vertex> eligibleVertices = buildBaseTraversal(g, targets);
return _run(g, eligibleVertices);
}
if (targets.size() <= BATCH_SIZE) {
GraphTraversal<Vertex, Vertex> eligibleVertices =
TraversalUtil.ruleTargetTraversal(g, targets);
return _run(g, eligibleVertices);
}

private GraphTraversal<Vertex, Vertex> buildBaseTraversal(
GraphTraversalSource g, List<AbstractRuleRunner.RuleRunnerTarget> targets) {
return TraversalUtil.ruleTargetTraversal(g, targets);
int totalBatches = (targets.size() + BATCH_SIZE - 1) / BATCH_SIZE;
List<Violation> allViolations = new ArrayList<>();

for (int batchNum = 0; batchNum < totalBatches; batchNum++) {
int fromIndex = batchNum * BATCH_SIZE;
int toIndex = Math.min(fromIndex + BATCH_SIZE, targets.size());
List<AbstractRuleRunner.RuleRunnerTarget> batch = targets.subList(fromIndex, toIndex);

GraphTraversal<Vertex, Vertex> batchTraversal =
TraversalUtil.ruleTargetTraversal(g, batch);
List<Violation> batchViolations = _run(g, batchTraversal);
allViolations.addAll(batchViolations);
}
return allViolations;
}

/**
Expand Down