added MARKER model to PathRetractionStrategy to reduce recurssive lookups of invalidating steps. Again, we really need Traversal.metdata to make this more 'pure'.
Project: http://git-wip-us.apache.org/repos/asf/tinkerpop/repo Commit: http://git-wip-us.apache.org/repos/asf/tinkerpop/commit/f1f65637 Tree: http://git-wip-us.apache.org/repos/asf/tinkerpop/tree/f1f65637 Diff: http://git-wip-us.apache.org/repos/asf/tinkerpop/diff/f1f65637 Branch: refs/heads/TINKERPOP-1642 Commit: f1f656377a1cf30792c389f9f670196017686eb6 Parents: b88b264 Author: Marko A. Rodriguez <okramma...@gmail.com> Authored: Fri Mar 17 13:04:58 2017 -0600 Committer: Stephen Mallette <sp...@genoprime.com> Committed: Mon Mar 20 14:09:03 2017 -0400 ---------------------------------------------------------------------- CHANGELOG.asciidoc | 3 ++- .../strategy/optimization/PathRetractionStrategy.java | 10 +++++++++- 2 files changed, 11 insertions(+), 2 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/f1f65637/CHANGELOG.asciidoc ---------------------------------------------------------------------- diff --git a/CHANGELOG.asciidoc b/CHANGELOG.asciidoc index 1d89305..59158cb 100644 --- a/CHANGELOG.asciidoc +++ b/CHANGELOG.asciidoc @@ -26,7 +26,8 @@ image::https://raw.githubusercontent.com/apache/tinkerpop/master/docs/static/ima TinkerPop 3.2.5 (Release Date: NOT OFFICIALLY RELEASED YET) ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -* `ProfileStrategy` now uses the marker-model to reduce recrussive lookups of `ProfileSideEffectStep`. +* `PathRetractionStrategy` now uses the marker-model to reduce recursive lookups of invalidating steps. +* `ProfileStrategy` now uses the marker-model to reduce recursive lookups of `ProfileSideEffectStep`. * `Mutating` steps now implement `Scoping` interface. * `LABELED_PATH` requirement is now set if any step in the traversal is labeled. * Added various metrics to the `GremlinGroovyScriptEngine` around script compilation and exposed them in Gremlin Server. http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/f1f65637/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/strategy/optimization/PathRetractionStrategy.java ---------------------------------------------------------------------- diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/strategy/optimization/PathRetractionStrategy.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/strategy/optimization/PathRetractionStrategy.java index bd27a3e..d19954b 100644 --- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/strategy/optimization/PathRetractionStrategy.java +++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/strategy/optimization/PathRetractionStrategy.java @@ -18,6 +18,7 @@ */ package org.apache.tinkerpop.gremlin.process.traversal.strategy.optimization; +import org.apache.tinkerpop.gremlin.process.computer.traversal.step.map.VertexProgramStep; import org.apache.tinkerpop.gremlin.process.traversal.Step; import org.apache.tinkerpop.gremlin.process.traversal.Traversal; import org.apache.tinkerpop.gremlin.process.traversal.TraversalStrategy; @@ -36,6 +37,7 @@ import org.apache.tinkerpop.gremlin.process.traversal.strategy.AbstractTraversal import org.apache.tinkerpop.gremlin.process.traversal.traverser.TraverserRequirement; import org.apache.tinkerpop.gremlin.process.traversal.util.PathUtil; import org.apache.tinkerpop.gremlin.process.traversal.util.TraversalHelper; +import org.apache.tinkerpop.gremlin.structure.Graph; import org.javatuples.Pair; import java.util.ArrayList; @@ -57,6 +59,7 @@ public final class PathRetractionStrategy extends AbstractTraversalStrategy<Trav // these strategies do strong rewrites involving path labeling and thus, should run prior to PathRetractionStrategy private static final Set<Class<? extends OptimizationStrategy>> PRIORS = new HashSet<>(Arrays.asList( RepeatUnrollStrategy.class, MatchPredicateStrategy.class, PathProcessorStrategy.class)); + private static final String MARKER = Graph.Hidden.hide("gremlin.pathRetraction"); private final int standardBarrierSize; @@ -72,8 +75,13 @@ public final class PathRetractionStrategy extends AbstractTraversalStrategy<Trav public void apply(final Traversal.Admin<?, ?> traversal) { // do not apply this strategy if there are lambdas as you can't introspect to know what path information the lambdas are using // do not apply this strategy if a PATH requirement step is being used (in the future, we can do PATH requirement lookhead to be more intelligent about its usage) - if (TraversalHelper.anyStepRecursively(step -> step instanceof LambdaHolder || step.getRequirements().contains(TraverserRequirement.PATH), TraversalHelper.getRootTraversal(traversal))) + if ((traversal.getParent() instanceof EmptyStep || traversal.getParent() instanceof VertexProgramStep) && + TraversalHelper.anyStepRecursively(step -> step instanceof LambdaHolder || step.getRequirements().contains(TraverserRequirement.PATH),traversal)) + TraversalHelper.applyTraversalRecursively(t -> t.getEndStep().addLabel(MARKER), traversal); + if (traversal.getEndStep().getLabels().contains(MARKER)) { + traversal.getEndStep().removeLabel(MARKER); return; + } final boolean onGraphComputer = TraversalHelper.onGraphComputer(traversal); final Set<String> foundLabels = new HashSet<>();