find_with_order 1.0.0 → 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ce3d6c02d373b47ed41758e0b88cee251fb6722a
4
- data.tar.gz: a89e7f837e84f7de799c809b4d3474987f0e9a86
3
+ metadata.gz: db2431c776b7124cdaa2e01efd6ec12bfdc1d513
4
+ data.tar.gz: 68f959361cc19eb381f94eb82028502f09b6f0f9
5
5
  SHA512:
6
- metadata.gz: 995d774548996433d25663c089a98322e81a78ad4be8ff4c1c8fab74ac8df59f50d42479201a57ce20dfcc764927247d5987695617823ca96473a0c0bcf69028
7
- data.tar.gz: d9d904897d1dcdcbe4816e50e908f241ae3910c8f249a0b5e2f9e1a414375de09a6fa858e9806a9905b355355d96be4bd4e0400c9d62cdbaf684f2c2f6211067
6
+ metadata.gz: bbe7b8e24e8afe6f51869f3dbac286f6361485b10229aa436ac395e69b6882291486747c6ea8d560650dff25e79bb59c0de577c20b49f12862f1c0caabc913da
7
+ data.tar.gz: 65080703b7bc52021f0e8096af1a591360afb238858761debc0e368b54e761c7061b36b23a7ec54ea53a8e51b81be166955a9d79d67df7232d66014d52f62ac3
data/README.md CHANGED
@@ -6,7 +6,7 @@
6
6
 
7
7
  # FindWithOrder
8
8
 
9
-
9
+ Find records in the same order of input array.
10
10
 
11
11
  ## Installation
12
12
 
@@ -43,6 +43,16 @@ User.where_with_order(:name, %w(Pearl John Kathenrie)).pluck(:name)
43
43
  # => ['Pearl', 'John', 'Kathenrie']
44
44
  ```
45
45
 
46
+ ## Benchmark
47
+
48
+ ```
49
+ user system total real
50
+ Find with order 0.030000 0.000000 0.030000 ( 0.033517)
51
+ Find then sort by index 1.510000 0.030000 1.540000 ( 1.706246)
52
+ Find then sort by hash mapping 1.120000 0.010000 1.130000 ( 1.192891)
53
+ ```
54
+ [test script](https://github.com/khiav223577/find_with_order/issues/4)
55
+
46
56
  ## Development
47
57
 
48
58
  After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
@@ -9,8 +9,8 @@ Gem::Specification.new do |spec|
9
9
  spec.authors = ["khiav reoy"]
10
10
  spec.email = ["mrtmrt15xn@yahoo.com.tw"]
11
11
 
12
- spec.summary = %q{Find records in the same order of input array.}
13
- spec.description = %q{Find records in the same order of input array. Supports Rails 3+.}
12
+ spec.summary = %q{A simple way to find records in the same order of input array.}
13
+ spec.description = %q{A simple way to find records in the same order of input array. Has better performance than manually sorting. Supports Rails 3+.}
14
14
  spec.homepage = "https://github.com/khiav223577/find_with_order"
15
15
  spec.license = "MIT"
16
16
 
@@ -5,7 +5,7 @@ class << ActiveRecord::Base
5
5
  def find_with_order(ids)
6
6
  return none if ids.blank?
7
7
  ids = ids.uniq
8
- return where(id: ids).order("field(id, #{ids.join(',')})").to_a
8
+ return where(id: ids).order("field(#{table_name}.id, #{ids.join(',')})").to_a
9
9
  end
10
10
  def where_with_order(column, ids)
11
11
  return none if ids.blank?
@@ -1,3 +1,3 @@
1
1
  module FindWithOrder
2
- VERSION = "1.0.0"
2
+ VERSION = "1.0.1"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: find_with_order
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - khiav reoy
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-02-23 00:00:00.000000000 Z
11
+ date: 2017-03-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -80,7 +80,8 @@ dependencies:
80
80
  - - ">="
81
81
  - !ruby/object:Gem::Version
82
82
  version: '0.3'
83
- description: Find records in the same order of input array. Supports Rails 3+.
83
+ description: A simple way to find records in the same order of input array. Has better
84
+ performance than manually sorting. Supports Rails 3+.
84
85
  email:
85
86
  - mrtmrt15xn@yahoo.com.tw
86
87
  executables: []
@@ -124,5 +125,5 @@ rubyforge_project:
124
125
  rubygems_version: 2.6.8
125
126
  signing_key:
126
127
  specification_version: 4
127
- summary: Find records in the same order of input array.
128
+ summary: A simple way to find records in the same order of input array.
128
129
  test_files: []