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

Add pagination to Issues page #5057

Merged
merged 2 commits into from
Aug 27, 2024

Conversation

nertc
Copy link
Contributor

@nertc nertc commented Aug 7, 2024

This PR addresses heavy calls and long load time of the Issues page. Problem was mentioned in #4990 by @AntonKhorev.

Added pagination functionality. When pagination buttons will be clicked, next or previous 50 issues will be called and displayed without a page refresh (Turbo will make a call and render returned Turbo Frame). In terms of performance, on the local environment I have 1000 users and 1000 issues. Initial loading time was decreased from ~8s to ~1s and after that every pagination needs ~150ms. In the real environment, it will have much better improvement, as instead of searching for 30000 issues, it will take only 50 (in theory, the difference should be 30x better in the real environment, then it is on my local machine). Because of the pagination functionality, now issues are sorted according to IDs (it should be the same sort as creation time sort).

To address @AntonKhorev 's comment about browser built-in search, user now can change ?limit=50 query parameter in the url to any number. Therefore, if any user wants to use browser built-in search, he can just change it, for example, to ?limit=10000 and 10000 issues will be rendered.

To address @nertc 's comment about clicking go back button of the browser, now every page is added to the browser history. Therefore, go back button will work fine, if user enters any report and then decides to go back to the list.

Video:

OpenStreetMap.and.47.more.pages.-.Work.-.Microsoft.Edge.2024-08-11.14-25-49.mp4

Issues not found:

image

User not found:

Screenshot 2024-08-19 220613

@nertc nertc marked this pull request as draft August 7, 2024 09:36
@nertc nertc force-pushed the issues_pagination_issues_page branch 2 times, most recently from b340779 to a63759c Compare August 7, 2024 10:11
@nertc
Copy link
Contributor Author

nertc commented Aug 7, 2024

Tests / Ubuntu 20.04, Ruby 3.0 (pull_request) has failed while checking test/controllers/changesets_controller_test.rb:324. I haven't changed anything in the "changesets controller". Therefore, I don't know if fixing it is in the scope of this PR. If it's okay to fix it in this PR, I'll add :wait => 1 to the end of the assertions. I think, it's some kind of Timing Issues.

@tomhughes
Copy link
Member

No please don't add random waits!

@tomhughes
Copy link
Member

Also why on earth does this need a whole load of javascript when all we're doing is adding next/previous page buttons? IF you want to do a partial load instead of reloading the whole page then you should be using turbo not doing it yourself.

@gravitystorm
Copy link
Collaborator

I agree with Tom here, the SPA-like behaviour should be implemented using the Turbo framework, not with custom javascript.

Otherwise, I'm happy to see pagination used for these pages. I would suggest just implementing the pagination first, then returning to the concept of using turbo drive separately, and ideally for all the paginated pages at the same time.

Using Turbo will also avoid having to define an extra page route, which doesn't fit into our resourceful-routing approach.

@tomhughes
Copy link
Member

Note that we already have #4646 to add turbo to everything that uses the server side pagination helpers.

@AntonKhorev
Copy link
Collaborator

and #4565 for changeset element pages

@nertc
Copy link
Contributor Author

nertc commented Aug 8, 2024

Thank you for review, I'll update this PR accordingly to use Turbo instead of the JS code.

@nertc nertc force-pushed the issues_pagination_issues_page branch from a63759c to cb5dffd Compare August 11, 2024 10:23
@nertc
Copy link
Contributor Author

nertc commented Aug 11, 2024

I updated this PR to handle navigation using Turbo. It depends on Turbo Frames functionality. On my local machine all calls (first load and navigation) now need ~1.5s instead of ~8s. I tried to decrease loading time of navigation (like it was with the last JS solution ~200ms), but both, using Turbo Streams and custom partial rendering endpoint (like it was in the last solution), required extra JS code for good navigation history, so I sticked to the current simpler solution.

Current solution solves @gravitystorm 's comment:

avoid having to define an extra page route

Thank you for linking your PRs, they were good examples.

@nertc nertc marked this pull request as ready for review August 11, 2024 10:58
@nertc nertc mentioned this pull request Aug 12, 2024
@nertc nertc force-pushed the issues_pagination_issues_page branch from cb5dffd to 3814fe2 Compare August 13, 2024 09:23
@nertc
Copy link
Contributor Author

nertc commented Aug 13, 2024

@AntonKhorev suggested a perfect solution in the comment of the PR #4646. I updated code according to the suggestion and without any sacrifice of performance, extra JS code or history management, pagination time was again decreased to ~150ms (previous solution needed ~1.5s).

@tomhughes
Copy link
Member

Right but ideally we don't want to be doing this to each user of pagination separately, we want to do it across all users which is what my PR is all about. I will be reviewing @AntonKhorev's suggestion in the context of that PR when I get time.

Copy link
Member

@tomhughes tomhughes left a comment

Choose a reason for hiding this comment

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

I think it might be better to split this into two commits - one that switches issues to use the common pagination helpers and a second to introduce turbo support.

<turbo-frame id="pagination" data-turbo-action="advance">
<% if @issues.length == 0 %>
<p><%= t(@user_not_found ? ".user_not_found" : ".issues_not_found") %></p>
<% else %>
Copy link
Member

Choose a reason for hiding this comment

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

I think this first branch should be outside the pagination frame because it's not actually paginated - only the else clause should be inside the frame as that is the part that can be navigated to different pages.

@@ -0,0 +1,40 @@
<turbo-frame id="pagination" data-turbo-action="advance">
Copy link
Member

Choose a reason for hiding this comment

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

This shouldn't have data-turbo-action but should have target="_top" and the advance action (and pagination as a target) should be on the next/previous buttons (which #4646 takes care of) so that other links inside the pagination section will break out to a full page load.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I agree with you. I wrote it this way for it to be both functional and not to conflict with #4646 after merging, but I'll change it back.


@issues, @newer_issues_id, @older_issues_id = get_page_items(@issues, :limit => @params[:limit])

render :partial => "page" if turbo_frame_request_id == "pagination" || turbo_frame_request_id == "search"
Copy link
Member

Choose a reason for hiding this comment

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

I think the second part of this condition is wrong (in fact it's not clear to be the search frame is needed at all) and instead the search form should have a data-turbo-frame="pagination" attribute to target loading of the pagination frame.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It was written to update only the list part of the page when the search button was clicked. But it may be out of scope of this PR (as it introduces new action other than pagination). I'll remove and it may be a separate PR when we will finish pagination functionality.

Copy link
Member

Choose a reason for hiding this comment

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

Right, but you can do that by telling the search form to target the pagination frame, which is all that is actually being updated given that is what you render.

If you thought the search form needed to be updated as well then the above should be rendering a larger section for search but I don't think that does need to be updated does, only the results (which are in the pagination frame) need to be updated?

:include_blank => t(".select_status"),
:data => { :behavior => "category_dropdown" },
:class => "form-select" %>
<turbo-frame id="search">
Copy link
Member

Choose a reason for hiding this comment

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

Do we actually need this frame? When does it get updated?

@nertc nertc force-pushed the issues_pagination_issues_page branch from 3814fe2 to 53bcd58 Compare August 19, 2024 18:36
@nertc
Copy link
Contributor Author

nertc commented Aug 19, 2024

@tomhughes Thank you for review. I updated PR according to your comments.

@nertc nertc force-pushed the issues_pagination_issues_page branch from 53bcd58 to 4ae4c60 Compare August 19, 2024 18:50
@tomhughes
Copy link
Member

As #4646 is merged now, can you rebase this on current master?

@nertc nertc force-pushed the issues_pagination_issues_page branch from 4ae4c60 to 5716817 Compare August 26, 2024 11:22
@nertc
Copy link
Contributor Author

nertc commented Aug 26, 2024

@tomhughes Sorry for the late reply. I rebased this branch. Now it has no conflicts with #4646.

click_on I18n.t("issues.page.older_issues")
assert_no_content I18n.t("issues.index.user_not_found")
assert_no_content I18n.t("issues.index.issues_not_found")
assert_css "tr", :count => 31, :wait => 1.5
Copy link
Member

Choose a reason for hiding this comment

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

I assume that :wait is a timeout? Why do we need that - what happens if we don't have it? Is there a default timeout that is too short or does it wait forever?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

When I run this test on my local machine, it succeeds even without :wait. But when I was pushing it to the GitHub, workflow tests were failing, because they were not waiting for paginated pages to be rendered. That's why I added :wait. Maybe there is some difference in the default waiting time configuration. I checked default_max_wait_time on my local machine and it was 2 (it's even more than the hardcoded 1.5).

Copy link
Member

Choose a reason for hiding this comment

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

That doesn't really make any sense - a shorter timeout shouldn't fix it. I suspect it was actually just chance that you set a timeout and then that run happened to work within the timeout.

All of which is why I hat tests which rely on timeouts, because they're not deterministic and can fail arbitrarily on different machines or even on the same machine under different conditions.

It seems it's unavoidable with browser based testing like this though, so I suspect we should just increase the default to 5 or 10 or something.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I agree with you, it seems strange. I thought, maybe default time of my local machine was different with the one of the versions of GitHub workflow tests. I'll remove it and push without :wait-s. Let's see if it still fails.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

All tests have passed. It's strange because in the first version all the tests were failing. Maybe changing a solution helped timing.

@nertc nertc force-pushed the issues_pagination_issues_page branch from 5716817 to 3cf5667 Compare August 27, 2024 07:51
Copy link
Member

@tomhughes tomhughes left a comment

Choose a reason for hiding this comment

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

Thanks for that change. I think this is good to go now...

@tomhughes tomhughes merged commit 5841813 into openstreetmap:master Aug 27, 2024
24 checks passed
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.

4 participants