[libcommhistory] Fix extremely slow groups query with lots of events

The full join on the Events table caused this query to take several
minutes to execute with 5000 events. Using a subquery reduces that to
under 500ms.

There is more room to optimize these queries later.
Merge pull request #31 from special/slow-query

[libcommhistory] Fix extremely slow groups query with lots of events