Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CV2-3776: implement a custom pagination for TiplineMessageType #1697

Merged
merged 6 commits into from
Oct 18, 2023

Conversation

melsawy
Copy link
Contributor

@melsawy melsawy commented Oct 17, 2023

Description

Currently to get the cursor we should retrieve all messages and the cursor is the index of the item not item ID so I implement a custom pagination to override current behavior for cursor to use item id instead of index of the item so I can retrieve a cursor for a specific message

so I did the following:

  • Add a cursor to TiplineMessageType so you can query a cursor for specific message
  • Override cursor_for method in a custom class
  • Override load_nodes method in a custom class

References: CV2-3776

How has this been tested?

Please describe the tests that you ran to verify your changes. Provide instructions so we can verify the changes. Please describe whether or not you implemented automated tests.

Things to pay attention to during code review

Please describe parts of the change that require extra attention during code review, for example:

  • File FFFF, line LL: This refactoring does this and this. Is it consistent with how it’s implemented elsewhere?
  • Etc.

Checklist

  • I have performed a self-review of my own code
  • I have added unit and feature tests, if the PR implements a new feature or otherwise would benefit from additional testing
  • I have added regression tests, if the PR fixes a bug
  • I have added logging, exception reporting, and custom tracing with any additional information required for debugging
  • I considered secure coding practices when writing this code. Any security concerns are noted above.
  • I have commented my code in hard-to-understand areas, if any
  • I have made needed changes to the README
  • My changes generate no new warnings
  • If I added a third party module, I included a rationale for doing so and followed our current guidelines

@melsawy melsawy changed the title CV2-3776: implement a custom pagination for graphql query CV2-3776: implement a custom pagination for TiplineMessageType Oct 18, 2023
@melsawy melsawy marked this pull request as ready for review October 18, 2023 05:01
items.where('id > ?', start_idx)
else
items
end
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

end at 20, 6 is not aligned with if at 8, 21.

index_from_cursor(after) > items.map(&:id).min
else
false
end
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

end at 30, 6 is not aligned with if at 22, 27.

index_from_cursor(before) < items.map(&:id).max
else
false
end
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

end at 40, 6 is not aligned with if at 32, 23.

def load_nodes
@nodes ||= begin
sliced_nodes = if before && after
end_idx = index_from_cursor(before)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use 2 (not -13) spaces for indentation.


@has_previous_page = if last
# There are items preceding the ones in this result
sliced_nodes.count > last
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use 2 (not -19) spaces for indentation.

Copy link
Contributor

@caiosba caiosba left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a very cool approach, Sawy! Can you please add a test for it (or update the previous one)?

@melsawy
Copy link
Contributor Author

melsawy commented Oct 18, 2023

That's a very cool approach, Sawy! Can you please add a test for it (or update the previous one)?

Already I did, updated the existing one

@melsawy melsawy requested a review from caiosba October 18, 2023 12:21
Copy link
Contributor

@caiosba caiosba left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just reviewed this in a call with Sawy - good to go once tests pass and Sawy makes the change we discussed about sorting.

@codeclimate
Copy link

codeclimate bot commented Oct 18, 2023

Code Climate has analyzed commit 37882af and detected 0 issues on this pull request.

The test coverage on the diff in this pull request is 100.0% (100% is the threshold).

This pull request will bring the total coverage in the repository to 100.0% (0.0% change).

View more on Code Climate.

@melsawy melsawy merged commit 9e08de3 into develop Oct 18, 2023
8 checks passed
@melsawy melsawy deleted the fix/CV2-3776-tipline-message-history-pagination branch October 18, 2023 18:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants