Skip to content

Commit

Permalink
chore: remove method that call count(*)
Browse files Browse the repository at this point in the history
  • Loading branch information
shaojunda committed Aug 11, 2020
1 parent 620f9c0 commit 15de5ee
Showing 1 changed file with 22 additions and 2 deletions.
24 changes: 22 additions & 2 deletions app/lib/fast_jsonapi/pagination_meta_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ def call
hash[:links][:self] = generate_url(page)

if page < total_pages
hash[:links][:next] = generate_url(records.next_page)
hash[:links][:last] = generate_url(records.total_pages)
hash[:links][:next] = generate_url(next_page)
hash[:links][:last] = generate_url(total_pages)
end

hash
Expand All @@ -39,6 +39,26 @@ def call
attr_reader :page, :page_size, :records, :records_counter, :total_count
attr_accessor :url, :hash

def current_page
records.current_page
end

def last_page?
current_page == total_pages
end

def next_page
current_page + 1 unless last_page? || out_of_range?
end

def last_page?
current_page == total_pages
end

def out_of_range?
current_page > total_pages
end

def generate_url(page)
[url, url_params(page)].join("?")
end
Expand Down

0 comments on commit 15de5ee

Please sign in to comment.