Thanks Zack.
That said, I was surprised to see that Ogre was fully materializing all query results before returning the first!!!
(From pipe.clj)
(defn first-of!
[^GremlinPipeline p]
(-> p into-vec! first))
(defn into-vec!
[^GremlinPipeline p]
(into [] (to-list! p)))
(defn to-list!
[^GremlinPipeline p]
(.toList p)) ;; bad news here
The key is that you are calling the .toList method on the GremlinPipeline, which collects *all* the results into a java.util.ArrayList. And then you are putting that into a Clojure vector, and then grabbing the first.
Note, you can create the pipeline and then call (next pipeline) and I believe it does the right thing:
(defn next
[^GremlinPipeline p i]
(.next p i))
Any reason you did not do it this way??
(defn to-lazy-list!
[^GremlinPipeline p depth]
(let [n (oq/next p 1)]
(if (and (first n) (> depth 0))
(cons n (lazy-seq (to-lazy-list! p (- depth 1))))
nil)))
The result is much faster (and I think better in many ways):
graph-explore.core> (time (oq/query
(ot/get-vertices)
oq/map
(to-lazy-list! 1)))
"Elapsed time: 0.807 msecs"
...
graph-explore.core> (time (oq/query
(ot/get-vertices)
oq/map
oq/first-of!))
"Elapsed time: 14.273 msecs"