Commit 4e9ec002 authored by Alper Akgun's avatar Alper Akgun Committed by Mike Jang

Doc for usage data batch counts by a grouped relation

parent 5eeb1b78
...@@ -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