The most concise solution I can think of though would be:

```ruby
    package_group_ids = package_group_rules.select(:present?).flat_map do |rule|
      PackageGroup.legacy_search(rule.name, 0, 0, [repo.pulp_id]).map(&:package_group_id).compact
    end
```

This would eliminate having to use compact and flatten.