Skip to content

Commit

Permalink
Implements NodeProxy#getRelationshipTypes w/ RelationshipGroupCursor
Browse files Browse the repository at this point in the history
Instead of always iterating over all the relationshis of a node
  • Loading branch information
tinwelint committed May 17, 2018
1 parent 5e7900d commit 2288ede
Showing 1 changed file with 5 additions and 9 deletions.
Expand Up @@ -19,9 +19,6 @@
*/
package org.neo4j.kernel.impl.core;

import org.eclipse.collections.api.set.primitive.MutableIntSet;
import org.eclipse.collections.impl.set.mutable.primitive.IntHashSet;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
Expand All @@ -44,7 +41,7 @@
import org.neo4j.internal.kernel.api.LabelSet;
import org.neo4j.internal.kernel.api.NodeCursor;
import org.neo4j.internal.kernel.api.PropertyCursor;
import org.neo4j.internal.kernel.api.RelationshipTraversalCursor;
import org.neo4j.internal.kernel.api.RelationshipGroupCursor;
import org.neo4j.internal.kernel.api.TokenRead;
import org.neo4j.internal.kernel.api.exceptions.EntityNotFoundException;
import org.neo4j.internal.kernel.api.exceptions.InvalidTransactionTypeKernelException;
Expand Down Expand Up @@ -747,22 +744,21 @@ public int getDegree( RelationshipType type, Direction direction )
public Iterable<RelationshipType> getRelationshipTypes()
{
KernelTransaction transaction = safeAcquireTransaction();
try ( RelationshipTraversalCursor relationships = transaction.cursors().allocateRelationshipTraversalCursor();
try ( RelationshipGroupCursor relationships = transaction.cursors().allocateRelationshipGroupCursor();
Statement ignore = transaction.acquireStatement() )
{
NodeCursor nodes = transaction.ambientNodeCursor();
TokenRead tokenRead = transaction.tokenRead();
singleNode( transaction, nodes );
nodes.allRelationships( relationships );
final MutableIntSet seen = new IntHashSet();
nodes.relationships( relationships );
List<RelationshipType> types = new ArrayList<>();
while ( relationships.next() )
{
// only include this type if there are any relationships with this type
int type = relationships.type();
if ( !seen.contains( type ) )
if ( relationships.totalCount() > 0 )
{
types.add( RelationshipType.withName( tokenRead.relationshipTypeName( relationships.type() ) ) );
seen.add( type );
}
}

Expand Down

0 comments on commit 2288ede

Please sign in to comment.