Commit d40db43b authored by Mike Jang's avatar Mike Jang

Merge branch...

Merge branch '255900-product-analytics-documentation-for-adapt-batchcount-for-grouped-records' into 'master'

Doc for usage data batch counts by a grouped relation

See merge request gitlab-org/gitlab!43811
parents e3ba2b1d 4e9ec002
...@@ -223,6 +223,25 @@ Examples: ...@@ -223,6 +223,25 @@ Examples:
sum(JiraImportState.finished, :imported_issues_count) sum(JiraImportState.finished, :imported_issues_count)
``` ```
### Grouping & Batch Operations
The `count`, `distinct_count`, and `sum` batch counters can accept an `ActiveRecord::Relation`
object, which groups by a specified column. With a grouped relation, the methods do batch counting,
handle errors, and returns a hash table of key-value pairs.
Examples:
```ruby
count(Namespace.group(:type))
# returns => {nil=>179, "Group"=>54}
distinct_count(Project.group(:visibility_level), :creator_id)
# returns => {0=>1, 10=>1, 20=>11}
sum(Issue.group(:state_id), :weight))
# returns => {1=>3542, 2=>6820}
```
### Redis Counters ### Redis Counters
Handles `::Redis::CommandError` and `Gitlab::UsageDataCounters::BaseCounter::UnknownEvent` Handles `::Redis::CommandError` and `Gitlab::UsageDataCounters::BaseCounter::UnknownEvent`
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment