This also looks a bit different in recent commits. 
https://github.com/mjjc/critiquebrainz/blob/oauth/webservice/app/models/publication.py
Now it all boils down to a "SELECT COUNT(*) ..." sql query.