Skip to content

Instantly share code, notes, and snippets.

@handshake-engineering-blog
Created April 19, 2021 20:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save handshake-engineering-blog/376996a93e7e6abdd1f013c0c95aae32 to your computer and use it in GitHub Desktop.
Save handshake-engineering-blog/376996a93e7e6abdd1f013c0c95aae32 to your computer and use it in GitHub Desktop.
1977385383_11
def results
@_results ||= begin
if direction == :forward
# If there’s an after cursor, decode it and only query for records with an id that come after that cursor
@items = @items.where('id > ?', Base64.decode64(@after_value)) if @after_value.present?
elsif direction == :backward
# If there’s a before cursor, decode it and only query for records with an id that come before that cursor
@items = @items.where('id < ?', Base64.decode64(@before_value)) if @before_value.present?
@items = @items.reverse_order
end
@items.limit(page_size + 1) # Fetch one extra result to determine if there's another page
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment