Hello everyone! Looking to get some help making this query more performant (and understand best practices while at it).
Let's say I have two nodes connected by a relationship WATCHED
like below. The WATCHED
relationship has property percentComplete
and the Content
node has liked
which is the number of users that liked a piece of content.
(:User)-[:WATCHED]-(:Content)
Ultimately, what I am trying to do is get a count of the total number of viewers, a count of the total number of viewers that have percentComplete at 100 and a count of users that liked a piece of content. Then I can determine the percentage of Users
that finished a video and the percentage of Users
that liked
a video.
Here is what I have so far - is there a way to do it without all of the WITH
/ MATCH
statements? Any issues / room for improvement you see?
MATCH (content)-[:WATCHED]-(viewer:User)
MATCH (content)-[r1:WATCHED]-(completer:User) WHERE r1.percentComplete = 100
WITH count(viewer) AS viewers, completer, content
WHERE viewers > 20
WITH count(completer) AS completed, content, viewers
WITH toInteger(toFloat(completed)/toFloat(viewers)*100) as percentComplete, completed, content, viewers
WITH toInteger(toFloat(content.liked)/toFloat(viewers)*100) AS percentLiked, percentComplete, completed, content, viewers
RETURN content.title AS title, completed, viewers, percentComplete, percentLiked, (percentLiked+percentComplete) / 2 AS score ORDER BY score DESC