gallery: optimize getTreeEvents() (get events/tree_events stats)