Non deprecated equivalent to fastest count

We're using Neo 4.4.3 and following the suggestions here, we're using the following as a way to get count of related nodes in the fastest possible way (as suggested here):

MATCH (c:Node {id: $nodeId})
RETURN size((c)-[:CONTAINS]->())

However, we're getting a warning

A pattern expression should only be used in order to test the existence of a pattern. It should therefore only be used in contexts that evaluate to a boolean, e.g. inside the function exists() or in a WHERE-clause. All other uses are deprecated and should be replaced by a pattern comprehension.

Problem is, all the alternatives detailed here are noticeable much, much slower and this is a time critical part of our front end.

Any suggestions as to have an alternative that does not trigger the deprecation warning?

Try the count subquery

MATCH (c:Node {id: $nodeId})
RETURN count{(c)-[:CONTAINS]->()}

The count { } syntax is not supported in our Neo version (4.4.3), are there other alternatives that work on 4.4.3?

Oops..the count subquery was introduced in 5.3 or so.

Since it is deprecated you can continue to use it until you upgrade and can migrate to the count subquery. It’s just a warning.

If you want to use list comprehension, it would be something like the following. I find this a convoluted approach to getting to the count.

MATCH (c:Node {id: $nodeId})
RETURN size([(c)-[:CONTAINS]->()|1])

You could use a subquery.

MATCH (c:Node {id: $nodeId})
Call {
  with c
  match (c)-[:CONTAINS]->()
  Return count(*) as cnt
}
RETURN cnt