Code Monkey home page Code Monkey logo

hightop's Issues

Relations

Can this be used to count ActiveRecord relations as well?

Case insensitive keys?

First off, great gem!

Second, it seems grouping is currently case sensitive:

{ "This Is A Key"=>57, "this is a key"=>6, "etc"=>6 }

Possible to include an option to ignore case?

Ruby 2.7 deprecation warnings

Hey!

I just stumbled across some deprecation warnings with hightop using Ruby 2.7.

# frozen_string_literal: true
# hightop.rb

require "bundler/inline"

gemfile(true) do
  source "https://rubygems.org"

  git_source(:github) { |repo| "https://github.com/#{repo}.git" }

  # Activate the gem you are reporting the issue against.
  gem "activerecord", "6.0.3"
  gem "sqlite3"
  gem "hightop", "0.2.2"
end

require "active_record"

# This connection will do for database-independent bug reports.
ActiveRecord::Base.establish_connection(adapter: "sqlite3", database: ":memory:")

ActiveRecord::Schema.define do
  create_table :posts, force: true do |t|
    t.timestamps null: false
    t.integer :visits
    t.string :visitor_token
  end
end

class Post < ActiveRecord::Base
end

(1..10).each { |visits| Post.create(visits: visits, visitor_token: SecureRandom.hex) }

Post.where('created_at > ?', 90.days.ago)
    .top(:visits, distinct: :visitor_token)
$ ruby hightop.rb
Fetching gem metadata from https://rubygems.org/........
Resolving dependencies...
Using concurrent-ruby 1.1.6
Using i18n 1.8.3
Using minitest 5.14.1
Using thread_safe 0.3.6
Using tzinfo 1.2.7
Using zeitwerk 2.3.0
Using activesupport 6.0.3
Using activemodel 6.0.3
Using activerecord 6.0.3
Using bundler 2.1.4
Using hightop 0.2.2
Using sqlite3 1.4.2
-- create_table(:posts, {:force=>true})
   -> 0.0044s
/ruby/gems/2.7.0/gems/hightop-0.2.2/lib/hightop/enumerable.rb:23: warning: Using the last argument as keyword parameters is deprecated; maybe ** should be added to the call
/ruby/gems/2.7.0/gems/hightop-0.2.2/lib/hightop/kicks.rb:3: warning: The called method `top' is defined here

I believe these are not from usage but from the library itself. It does not happen if you remove the .where call or the .top call.

$ ruby hightop.rb
Fetching gem metadata from https://rubygems.org/........
Resolving dependencies...
Using concurrent-ruby 1.1.6
Using i18n 1.8.3
Using minitest 5.14.1
Using thread_safe 0.3.6
Using tzinfo 1.2.7
Using zeitwerk 2.3.0
Using activesupport 6.0.3
Using activemodel 6.0.3
Using activerecord 6.0.3
Using bundler 2.1.4
Using hightop 0.2.2
Using sqlite3 1.4.2
-- create_table(:posts, {:force=>true})
   -> 0.0043s

Default scope messes with Hightop

Given:

[24] pry(main)> Recognition.top(:sender_company_id, 10)
   (144.6ms)  SELECT  COUNT(*) AS count_all, sender_company_id AS sender_company_id FROM `recognitions`  WHERE `recognitions`.`deleted_at` IS NULL AND (sender_company_id IS NOT NULL) GROUP BY `recognitions`.`sender_company_id`  ORDER BY recognitions.created_at DESC, recognitions.id DESC, count_all DESC, sender_company_id LIMIT 10
=> {8132=>1, 4379=>2, 8126=>3, 1665=>1, 8122=>1, 7760=>11, 5305=>1, 8105=>3, 8104=>2, 6417=>1}

[25] pry(main)> Recognition.top(:sender_company_id, min: 1000)
   (148.7ms)  SELECT COUNT(*) AS count_all, sender_company_id AS sender_company_id FROM `recognitions`  WHERE `recognitions`.`deleted_at` IS NULL AND (sender_company_id IS NOT NULL) GROUP BY `recognitions`.`sender_company_id` HAVING COUNT(*) >= 1000  ORDER BY recognitions.created_at DESC, recognitions.id DESC, count_all DESC, sender_company_id
=> {3552=>3775,
 3744=>1952,
 5790=>4211,
 4415=>10285,
 3724=>1032,
 1591=>13545,
 3000=>2289,
 2967=>2385,
 2308=>1320,
 2146=>23427,
 1936=>1899,
 1512=>2494,
 323=>1506,
 1=>9577}

You can see in the first call which uses the limit syntax, I do not get the expected results because of default scope which adds a default order clause.

Should hightop ignore default scopes, or should it issue warning if they exist?

Recognition.unscoped.top(:sender_company_id, 10) works as expected

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.