Speed up counting by using a JOIN

Note this will double count disk usage as it doesn't take into account
the fact that attachments are re-attached to each subsequent edition.