Skip to content

Commit 1df6c1a

Browse files
authored
Merge pull request #719 from nervosnetwork/shaojunda-remove-count-on-pagination-generator
chore: remove method that call count(*)
2 parents 620f9c0 + 15de5ee commit 1df6c1a

File tree

1 file changed

+22
-2
lines changed

1 file changed

+22
-2
lines changed

app/lib/fast_jsonapi/pagination_meta_generator.rb

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ def call
2727
hash[:links][:self] = generate_url(page)
2828

2929
if page < total_pages
30-
hash[:links][:next] = generate_url(records.next_page)
31-
hash[:links][:last] = generate_url(records.total_pages)
30+
hash[:links][:next] = generate_url(next_page)
31+
hash[:links][:last] = generate_url(total_pages)
3232
end
3333

3434
hash
@@ -39,6 +39,26 @@ def call
3939
attr_reader :page, :page_size, :records, :records_counter, :total_count
4040
attr_accessor :url, :hash
4141

42+
def current_page
43+
records.current_page
44+
end
45+
46+
def last_page?
47+
current_page == total_pages
48+
end
49+
50+
def next_page
51+
current_page + 1 unless last_page? || out_of_range?
52+
end
53+
54+
def last_page?
55+
current_page == total_pages
56+
end
57+
58+
def out_of_range?
59+
current_page > total_pages
60+
end
61+
4262
def generate_url(page)
4363
[url, url_params(page)].join("?")
4464
end

0 commit comments

Comments
 (0)