chop one query by caching the exclusions (bug 869715)

for @robhudson

plus some cleaning