Commit 2e975d31c06021c7f213fb1619819bc5dc89d0f0

Authored by Raúl Rodríguez
Committed by GitHub
1 parent 9b327ab3

Replace uniq with distinct in the code samples from the readme (#1502)

Showing 1 changed file with 4 additions and 4 deletions   Show diff stats
README.md
... ... @@ -649,7 +649,7 @@ class Product < ApplicationRecord
649 649 def search_data
650 650 {
651 651 name: name,
652   - conversions: searches.group(:query).uniq.count(:user_id)
  652 + conversions: searches.group(:query).distinct.count(:user_id)
653 653 # {"ice cream" => 234, "chocolate" => 67, "cream" => 2}
654 654 }
655 655 end
... ... @@ -1586,14 +1586,14 @@ class ReindexConversionsJob < ApplicationJob
1586 1586 # get records that have a recent conversion
1587 1587 recently_converted_ids =
1588 1588 Searchjoy::Search.where("convertable_type = ? AND converted_at > ?", class_name, 1.day.ago)
1589   - .order(:convertable_id).uniq.pluck(:convertable_id)
  1589 + .order(:convertable_id).distinct.pluck(:convertable_id)
1590 1590  
1591 1591 # split into groups
1592 1592 recently_converted_ids.in_groups_of(1000, false) do |ids|
1593 1593 # fetch conversions
1594 1594 conversions =
1595 1595 Searchjoy::Search.where(convertable_id: ids, convertable_type: class_name)
1596   - .group(:convertable_id, :query).uniq.count(:user_id)
  1596 + .group(:convertable_id, :query).distinct.count(:user_id)
1597 1597  
1598 1598 # group conversions by record
1599 1599 conversions_by_record = {}
... ... @@ -1845,7 +1845,7 @@ class Product < ApplicationRecord
1845 1845 def search_data
1846 1846 {
1847 1847 name: name,
1848   - unique_user_conversions: searches.group(:query).uniq.count(:user_id),
  1848 + unique_user_conversions: searches.group(:query).distinct.count(:user_id),
1849 1849 # {"ice cream" => 234, "chocolate" => 67, "cream" => 2}
1850 1850 total_conversions: searches.group(:query).count
1851 1851 # {"ice cream" => 412, "chocolate" => 117, "cream" => 6}
... ...