WIP: A bunch of perf optimizations

This is still WIP but I'm far enough along that I thought I'd open a PR.  This began as an attempt to properly implement the optimization I tried in cb245d3d0fc6d85c38ffe3fa07125c09e8ed2049 for #1749. However, in order to use the new `FilterableItemRepository` from our hook collections, I've had to do a bunch of refactorings, and as part of those refactorings I've been finding a lot of small optimizations and general code organization improvements.  Whoever reviews this may want to do it commit-by-commit as the diff is pretty big and it's probably easier to follow by looking at the individual commits.  There's also more to come -- I'm at a point where I can use `FilterableItemRepository` from the hook collections but there are a handful of failing specs to fix first.