Replace inefficient, slow link count query.

The query before wasn't actually doing anything different from a simple
count, and was taking ~14 seconds to run in some cases!  Replaced with
a simple, faster count.