Update the collection count cache in more cases

I don't know if this covers all cases, but it's definitely better than
before.