fast_page 0.1.3 → 0.1.5

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
  SHA256:
3
- metadata.gz: c34b1767bb6dbece4339563801e4212941e680f6126addeadb4b454a77373c9c
4
- data.tar.gz: 2c30353c390161c8b37d12bddc30ef0f1f29fabcb0fe77ab950ca67fa6eee33c
3
+ metadata.gz: de1e2b8f0b21925323aefa089bb2d884adaa10bd2fc329541773865de40f000f
4
+ data.tar.gz: 3a94d8ffb42cc5b766e1daf4f0092b2b75266e139d358e63179ee418300ffa9a
5
5
  SHA512:
6
- metadata.gz: f8edd90c67bf113d202ceb88f6815fd25184a55cb6917a618143acc5f18aabcbfe60288051eada0ea2ca646b2f910d4f4d8e367d9f191ad8f253c20809bcdfdf
7
- data.tar.gz: 179b2f74676f2c76624f54fdb35697956dae55b14668f0b49154840da60604dedc74da0b16e5555d5e85aa3e184a75044ee5fa7071597ac32d43ba7bc248639b
6
+ metadata.gz: 990f0e5c32843a9f06116195132a2ec87f986b155f76da6962a896de5b2cd67fea09083ba0c200af944c76c0d3d189881cf5ebabf2ed38a03476a77eaefa0e89
7
+ data.tar.gz: 668bcf9f45b90a7225022859f736f79c5b128025cf5c7ee6e7aa8e7f8c2dbcf4538a70a8c92c355c7386d45609067b74c941e3570e2efeabbacd9a02c5c87a18
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- fast_page (0.1.2)
4
+ fast_page (0.1.4)
5
5
  activerecord
6
6
  activesupport
7
7
 
data/README.md CHANGED
@@ -2,6 +2,8 @@
2
2
 
3
3
  **`FastPage` applies the MySQL "deferred join" optimization to your ActiveRecord offset/limit queries.⚡️**
4
4
 
5
+ [![See on RubyGems](https://badge.fury.io/rb/fast_page.svg)](https://badge.fury.io/rb/fast_page)
6
+
5
7
  ## Usage
6
8
 
7
9
  Add `fast_page` to your Gemfile.
@@ -6,17 +6,27 @@ module FastPage
6
6
  # Must have a limit or offset defined
7
7
  raise ArgumentError, "You must specify a limit or offset to use fast_page" if !limit_value && !offset_value
8
8
 
9
+ # We load 1 additional record to determine if there is a next page.
10
+ # This helps us avoid doing a count over all records
11
+ @values[:limit] = limit_value + 1 if limit_value
9
12
  id_scope = dup
10
13
  id_scope = id_scope.except(:includes) unless references_eager_loaded_tables?
11
14
  ids = id_scope.pluck(:id)
12
15
 
16
+ if limit_value
17
+ @values[:limit] = limit_value - 1
18
+ # Record if there is a next page
19
+ @_has_next = ids.length > limit_value
20
+ ids = ids.first(limit_value)
21
+ end
22
+
13
23
  if ids.empty?
14
24
  @records = []
15
25
  @loaded = true
16
26
  return self
17
27
  end
18
28
 
19
- @records = where(id: ids).unscope(:limit).unscope(:offset).load
29
+ @records = where(id: ids).unscope(:limit).unscope(:offset).load.records
20
30
  @loaded = true
21
31
 
22
32
  self
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module FastPage
4
- VERSION = "0.1.3"
4
+ VERSION = "0.1.5"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fast_page
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mike Coutermarsh
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-08-16 00:00:00.000000000 Z
11
+ date: 2022-12-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord