CMFActivity: Reduce distribution query count
The first commit is to fix an unrelated issue, which was discovered while testing the main change.
The main change groups the lookup of activities which would forbid a group of activities from being validated: instead of checking all dependencies for a single activity (typically, tihs means one query for one, and rarely two, dependency type(s)), this change does one query for any number of activities to be validated, but for a single dependency type. The result is:
- fewer queries overall
- a simpler execution plan for each activity, to compensate for the increased number of values a column is tested against