Conditional Target vertex for syntax v2

Hi there! I would second what Mark said, on the condition that you might Transactions to be directly connected. If the Transactions are indirectly connected via some intermediate vertices, then there’s not much to improve here, except that you could split out the select statement in the WHILE loop to something like the following

neighbors = 
  SELECT t FROM Source:s -(e_type:e)-> v_type:t
  WHERE ...
  ACCUM ...
Source =
  SELECT t FROM neighbors:s -(e_type:e)-> Transaction:t
  WHERE ...
  ACCUM ...
ResultSet = ResultSet UNION Source;

This optimization is assuming that the reason for your slowdown is because those intermediate vertices have neighbors of a type other than Transaction that are being needlessly included in the select statement.
Note that you can also remove that ORDER BY clause, since I’m not sure what it’s adding.

1 Like