Skip to content

Commit

Permalink
Merge pull request #769 from jsight/reporting_speed_fixes
Browse files Browse the repository at this point in the history
Reporting speed fixes
  • Loading branch information
jsight committed Dec 2, 2015
2 parents 9575fc8 + bbbafff commit e13b5c1
Show file tree
Hide file tree
Showing 20 changed files with 493 additions and 221 deletions.
5 changes: 5 additions & 0 deletions graph/api/src/main/java/org/jboss/windup/graph/Indexed.java
Expand Up @@ -25,4 +25,9 @@
* The type of index to be created.
*/
IndexType value() default IndexType.DEFAULT;

/**
* Indicates the type for the property. The default is {@link String}.
*/
Class<?> dataType() default String.class;
}
@@ -1,5 +1,8 @@
package org.jboss.windup.graph.model;

import java.util.HashSet;
import java.util.Set;

import org.jboss.windup.graph.model.resource.FileModel;

import com.tinkerpop.blueprints.Direction;
Expand Down Expand Up @@ -194,8 +197,15 @@ public interface ProjectModel extends WindupVertexFrame
@JavaHandler
ProjectModel getRootProjectModel();

/**
* Returns this project model as well as all of its children, recursively.
*/
@JavaHandler
Set<ProjectModel> getAllProjectModels();

abstract class Impl implements ProjectModel, JavaHandlerContext<Vertex>
{
@Override
public ProjectModel getRootProjectModel()
{
ProjectModel projectModel = this;
Expand All @@ -209,5 +219,14 @@ public ProjectModel getRootProjectModel()
return frame(projectModel.asVertex());
}

@Override
public Set<ProjectModel> getAllProjectModels()
{
Set<ProjectModel> result = new HashSet<>();
result.add(frame(it(), ProjectModel.class));
for (ProjectModel child : getChildProjects())
result.addAll(child.getAllProjectModels());
return result;
}
}
}
Expand Up @@ -5,7 +5,6 @@
import java.nio.file.Path;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;
Expand Down Expand Up @@ -165,9 +164,9 @@ public Graph configure(Graph baseGraph, FramedGraphConfiguration config)

private void initializeTitanIndexes(TitanGraph titanGraph)
{
Set<String> defaultIndexKeys = new HashSet<>();
Set<String> searchIndexKeys = new HashSet<>();
Set<String> listIndexKeys = new HashSet<>();
Map<String, Class<?>> defaultIndexKeys = new HashMap<>();
Map<String, Class<?>> searchIndexKeys = new HashMap<>();
Map<String, Class<?>> listIndexKeys = new HashMap<>();

Set<Class<? extends WindupVertexFrame>> modelTypes = graphTypeManager.getRegisteredTypes();
for (Class<? extends WindupVertexFrame> type : modelTypes)
Expand All @@ -180,18 +179,19 @@ private void initializeTitanIndexes(TitanGraph titanGraph)
Property property = Annotations.getAnnotation(method, Property.class);
if (property != null)
{
Class<?> dataType = index.dataType();
switch (index.value())
{
case DEFAULT:
defaultIndexKeys.add(property.value());
defaultIndexKeys.put(property.value(), dataType);
break;

case SEARCH:
searchIndexKeys.add(property.value());
searchIndexKeys.put(property.value(), dataType);
break;

case LIST:
listIndexKeys.add(property.value());
listIndexKeys.put(property.value(), dataType);
break;

default:
Expand All @@ -206,28 +206,45 @@ private void initializeTitanIndexes(TitanGraph titanGraph)
* This is the root Model index that enables us to query on frame-type (by subclass type, etc.) Without this, every typed query would be slow.
* Do not remove this unless something really paradigm-shifting has happened.
*/
listIndexKeys.add(WindupVertexFrame.TYPE_PROP);
listIndexKeys.put(WindupVertexFrame.TYPE_PROP, String.class);

log.info("Detected and initialized [" + defaultIndexKeys.size() + "] default indexes: " + defaultIndexKeys);
log.info("Detected and initialized [" + searchIndexKeys.size() + "] search indexes: " + searchIndexKeys);
log.info("Detected and initialized [" + listIndexKeys.size() + "] list indexes: " + listIndexKeys);

TitanManagement titan = titanGraph.getManagementSystem();
for (String key : defaultIndexKeys)
for (Map.Entry<String, Class<?>> entry : defaultIndexKeys.entrySet())
{
PropertyKey propKey = titan.makePropertyKey(key).dataType(String.class).cardinality(Cardinality.SINGLE).make();
String key = entry.getKey();
Class<?> dataType = entry.getValue();

PropertyKey propKey = titan.makePropertyKey(key).dataType(dataType).cardinality(Cardinality.SINGLE).make();
titan.buildIndex(key, Vertex.class).addKey(propKey).buildCompositeIndex();
}

for (String key : searchIndexKeys)
for (Map.Entry<String, Class<?>> entry : searchIndexKeys.entrySet())
{
PropertyKey propKey = titan.makePropertyKey(key).dataType(String.class).cardinality(Cardinality.SINGLE).make();
titan.buildIndex(key, Vertex.class).addKey(propKey, Mapping.STRING.getParameter()).buildMixedIndex("search");
String key = entry.getKey();
Class<?> dataType = entry.getValue();

if (dataType == String.class)
{
PropertyKey propKey = titan.makePropertyKey(key).dataType(String.class).cardinality(Cardinality.SINGLE).make();
titan.buildIndex(key, Vertex.class).addKey(propKey, Mapping.STRING.getParameter()).buildMixedIndex("search");
}
else
{
PropertyKey propKey = titan.makePropertyKey(key).dataType(dataType).cardinality(Cardinality.SINGLE).make();
titan.buildIndex(key, Vertex.class).addKey(propKey).buildMixedIndex("search");
}
}

for (String key : listIndexKeys)
for (Map.Entry<String, Class<?>> entry : listIndexKeys.entrySet())
{
PropertyKey propKey = titan.makePropertyKey(key).dataType(String.class).cardinality(Cardinality.LIST).make();
String key = entry.getKey();
Class<?> dataType = entry.getValue();

PropertyKey propKey = titan.makePropertyKey(key).dataType(dataType).cardinality(Cardinality.LIST).make();
titan.buildIndex(key, Vertex.class).addKey(propKey).buildCompositeIndex();
}

Expand Down
Expand Up @@ -11,6 +11,7 @@
import org.jboss.windup.reporting.model.InlineHintModel;
import org.jboss.windup.reporting.service.InlineHintService;
import org.jboss.windup.rules.files.model.FileReferenceModel;
import org.jboss.windup.util.ExecutionStatistics;
import org.ocpsoft.rewrite.context.EvaluationContext;
import org.ocpsoft.rewrite.param.ParameterStore;
import org.ocpsoft.rewrite.param.Parameterized;
Expand All @@ -30,51 +31,59 @@ public class HasHint extends AbstractIterationFilter<WindupVertexFrame> implemen
@Override
public boolean evaluate(GraphRewrite event, EvaluationContext context, WindupVertexFrame payload)
{
boolean result = false;
InlineHintService service = new InlineHintService(event.getGraphContext());

if (payload instanceof FileReferenceModel)
ExecutionStatistics.get().begin(HasHint.class.getCanonicalName());
try
{
Iterable<InlineHintModel> hints = service.getHintsForFileReference((FileReferenceModel) payload);
if (messagePattern == null)
{
result = hints.iterator().hasNext();
}
else
boolean result = false;
InlineHintService service = new InlineHintService(event.getGraphContext());

if (payload instanceof FileReferenceModel)
{
for (InlineHintModel c : hints)
Iterable<InlineHintModel> hints = service.getHintsForFileReference((FileReferenceModel) payload);
if (messagePattern == null)
{
ParameterizedPatternResult parseResult = messagePattern.parse(c.getHint());
if (parseResult.matches() && parseResult.isValid(event, context))
result = hints.iterator().hasNext();
}
else
{
for (InlineHintModel c : hints)
{
result = true;
break;
ParameterizedPatternResult parseResult = messagePattern.parse(c.getHint());
if (parseResult.matches() && parseResult.isValid(event, context))
{
result = true;
break;
}
}
}
}
}

if (payload instanceof FileModel)
{
Iterable<InlineHintModel> hints = service.getHintsForFile((FileModel) payload);
if (messagePattern == null)
if (payload instanceof FileModel)
{
result = hints.iterator().hasNext();
}
else
{
for (InlineHintModel c : hints)
Iterable<InlineHintModel> hints = service.getHintsForFile((FileModel) payload);
if (messagePattern == null)
{
result = hints.iterator().hasNext();
}
else
{
ParameterizedPatternResult parseResult = messagePattern.parse(c.getHint());
if (parseResult.matches() && parseResult.isValid(event, context))
for (InlineHintModel c : hints)
{
result = true;
break;
ParameterizedPatternResult parseResult = messagePattern.parse(c.getHint());
if (parseResult.matches() && parseResult.isValid(event, context))
{
result = true;
break;
}
}
}
}
return result;
}
finally
{
ExecutionStatistics.get().end(HasHint.class.getCanonicalName());
}
return result;
}

/**
Expand Down
Expand Up @@ -2,12 +2,13 @@

import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Set;
import java.util.logging.Logger;
import org.apache.commons.lang.StringUtils;

import org.apache.commons.lang.StringUtils;
import org.jboss.forge.furnace.util.Assert;
import org.jboss.windup.config.GraphRewrite;
import org.jboss.windup.config.parameters.ParameterizedIterationOperation;
Expand All @@ -16,7 +17,10 @@
import org.jboss.windup.graph.service.GraphService;
import org.jboss.windup.reporting.model.InlineHintModel;
import org.jboss.windup.reporting.model.Severity;
import org.jboss.windup.reporting.service.TagSetService;
import org.jboss.windup.rules.files.model.FileLocationModel;
import org.jboss.windup.util.ExecutionStatistics;
import org.jboss.windup.util.Logging;
import org.ocpsoft.rewrite.config.OperationBuilder;
import org.ocpsoft.rewrite.config.Rule;
import org.ocpsoft.rewrite.context.EvaluationContext;
Expand All @@ -26,9 +30,9 @@
/**
* Used as an intermediate to support the addition of {@link InlineHintModel} objects to the graph via an Operation.
*/
public class Hint extends ParameterizedIterationOperation<FileLocationModel> implements HintText, HintLink, HintSeverity, HintEffort
public class Hint extends ParameterizedIterationOperation<FileLocationModel>implements HintText, HintLink, HintSeverity, HintEffort
{
private static final Logger log = Logger.getLogger(Hint.class.getName());
private static final Logger LOG = Logging.get(Hint.class);

public static final Severity DEFAULT_SEVERITY = Severity.OPTIONAL;

Expand Down Expand Up @@ -93,50 +97,58 @@ public static HintText withText(String text)
}

@Override
public void performParameterized(GraphRewrite event, EvaluationContext context, FileLocationModel locationModel)
{
GraphService<InlineHintModel> service = new GraphService<>(event.getGraphContext(), InlineHintModel.class);

InlineHintModel hintModel = service.create();
hintModel.setRuleID(((Rule) context.get(Rule.class)).getId());
hintModel.setLineNumber(locationModel.getLineNumber());
hintModel.setColumnNumber(locationModel.getColumnNumber());
hintModel.setLength(locationModel.getLength());
hintModel.setFileLocationReference(locationModel);
hintModel.setFile(locationModel.getFile());
hintModel.setEffort(effort);
hintModel.setSeverity(this.severity);
if (hintTitlePattern != null)
{
hintModel.setTitle(hintTitlePattern.getBuilder().build(event, context));
}
else
public void performParameterized(final GraphRewrite event, final EvaluationContext context, final FileLocationModel locationModel)
{
ExecutionStatistics.get().begin("Hint.performParameterized");
try
{
// If there is no title, just use the description of the location
// (eg, 'Constructing com.otherproduct.Foo()')
hintModel.setTitle(locationModel.getDescription());
GraphService<InlineHintModel> service = new GraphService<>(event.getGraphContext(), InlineHintModel.class);

InlineHintModel hintModel = service.create();
hintModel.setRuleID(((Rule) context.get(Rule.class)).getId());
hintModel.setLineNumber(locationModel.getLineNumber());
hintModel.setColumnNumber(locationModel.getColumnNumber());
hintModel.setLength(locationModel.getLength());
hintModel.setFileLocationReference(locationModel);
hintModel.setFile(locationModel.getFile());
hintModel.setEffort(effort);
hintModel.setSeverity(this.severity);
if (hintTitlePattern != null)
{
hintModel.setTitle(hintTitlePattern.getBuilder().build(event, context));
}
else
{
// If there is no title, just use the description of the location
// (eg, 'Constructing com.otherproduct.Foo()')
hintModel.setTitle(locationModel.getDescription());
}
String hintText = hintTextPattern.getBuilder().build(event, context);
hintModel.setHint(hintText);

GraphService<LinkModel> linkService = new GraphService<>(event.getGraphContext(), LinkModel.class);
for (Link link : links)
{
LinkModel linkModel = linkService.create();
linkModel.setDescription(link.getTitle());
linkModel.setLink(link.getLink());
hintModel.addLink(linkModel);
}

Set<String> tags = new HashSet<>(this.getTags());
TagSetService tagSetService = new TagSetService(event.getGraphContext());
hintModel.setTagModel(tagSetService.getOrCreate(event, tags));

if (locationModel.getFile() instanceof SourceFileModel)
((SourceFileModel) locationModel.getFile()).setGenerateSourceReport(true);

LOG.info("Hint added to " + locationModel.getFile().getPrettyPathWithinProject() + " [" + this.toString(hintModel.getTitle(), hintText)
+ "] with tags: " + StringUtils.join(this.getTags(), " "));
}

String hintText = hintTextPattern.getBuilder().build(event, context);
hintModel.setHint(hintText);

GraphService<LinkModel> linkService = new GraphService<>(event.getGraphContext(), LinkModel.class);
for (Link link : links)
finally
{
LinkModel linkModel = linkService.create();
linkModel.setDescription(link.getTitle());
linkModel.setLink(link.getLink());
hintModel.addLink(linkModel);
ExecutionStatistics.get().end("Hint.performParameterized");
}

hintModel.setTags(this.getTags());

if (locationModel.getFile() instanceof SourceFileModel)
((SourceFileModel) locationModel.getFile()).setGenerateSourceReport(true);

log.info("Hint added to " + locationModel.getFile().getPrettyPathWithinProject()
+ " [" + this.toString(hintModel.getTitle(), hintText) + "] ");
log.info("Tags: " + StringUtils.join(this.getTags(), " "));
}

@Override
Expand All @@ -163,6 +175,7 @@ public HintLink with(Link link)
/**
* Set the inner hint text on this instance.
*/

protected void setText(String text)
{
this.hintTextPattern = new RegexParameterizedPatternParser(text);
Expand Down

0 comments on commit e13b5c1

Please sign in to comment.