Skip to content

Fix user activity pagination when there are hidden items#8202

Merged
leio10 merged 6 commits intodecidim:developfrom
mainio:fix/user-activity-pagination
Jul 20, 2021
Merged

Fix user activity pagination when there are hidden items#8202
leio10 merged 6 commits intodecidim:developfrom
mainio:fix/user-activity-pagination

Conversation

@ahukkanen
Copy link
Copy Markdown
Contributor

@ahukkanen ahukkanen commented Jul 14, 2021

🎩 What? Why?

Right now if there are hidden items (e.g. private space items or moderated items) included in the user's activity page, they will mess up the pagination on that page.

This happens because rather than filtering out these items directly from the results, the activities cell will call visible_for? for each of the activity items individually:

activity.visible_for?(current_user)

This is detached from the activity results which is used for the pagination:

<%= decidim_paginate activities %>

This fixes the issue by directly filtering out these items from the activity query.

Testing

  • Seed the development app
  • Create comments in both participatory processes the seeds created
  • Make one of these processes private
  • Moderate one of the user's comments in the public process
  • Go to the user's public profile activity view when logged out
  • See that the pagination is not working correctly

📋 Checklist

  • CONSIDER adding a unit test if your PR resolves an issue.
  • ✔️ DO check open PR's to avoid duplicates.
  • ✔️ DO keep pull requests small so they can be easily reviewed.
  • ✔️ DO build locally before pushing.
  • ✔️ DO make sure tests pass.
  • ✔️ DO make sure any new changes are documented in docs/.
  • ✔️ DO add and modify seeds if necessary.
  • ✔️ DO add CHANGELOG upgrade notes if required.
  • ✔️ DO add to GraphQL API if there are new public fields.
  • ✔️ DO add link to MetaDecidim if it's a new feature.
  • AVOID breaking the continuous integration build.
  • AVOID making significant changes to the overall architecture.

@leio10 leio10 added in-review module: core type: fix PRs that implement a fix for a bug labels Jul 19, 2021
Copy link
Copy Markdown
Contributor

@leio10 leio10 left a comment

Choose a reason for hiding this comment

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

Awesome work! 👏
I've found situations similar to this one and I wasn't able to build a query to include the relationships with all possible spaces at once.

)
end

query
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

💬 I'm a bit worried about the performance and the mantainability of these queries, but I can't find a better approach, so let's merge it and see how it works. 🤷‍♂️ 😕

Copy link
Copy Markdown
Contributor Author

@ahukkanen ahukkanen Jul 19, 2021

Choose a reason for hiding this comment

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

@leio10

Regarding performance

Generally performance is not an issue to worry about unless the query takes a really long time to execute and it is run very often. This query falls into neither of those categories.

In fact, I think the general advice regarding performance is that you should do as much as possible at the DB layer.

This change will obviously make the query less performant than the original but here we are only talking about some milliseconds which is nothing.

I ran EXPLAIN ANALYZE on both of these queries on an instance with a short of 90k users and a user that has over 3k action log items in total or 1.5k public action log items that would be visible there.

The results are:

Query Planning time Execution time Total time
Original 0.355ms 0.064ms 0.419ms
Modified (PR) 5.560ms 0.230ms 5.790ms
Difference 5.205ms (or 15.66x slower) 0.166ms (or 3.59x slower) 5.371ms (or 13.82x slower)

So can you see it's significantly slower (~14-15 times slower) but we are only talking about a difference of ~5ms here. It's not going to be noticeable.


Regarding maintainability

You are correct that it makes it more difficult to maintain but I don't know another way which wouldn't be significantly less performant than the proposed solution. Such as pre-counting the visibility for all records which would take potentially a very long time with a lot of records. Maybe the private space activities should be completely hidden from the activity log (?), which would make it easier, but then it would change existing behavior.

For moderated action log items you could create some logic that would change a flag in the action logs table when the item is hidden by moderation. But I think that's conceptually wrong because then the action log items would have to be touched afterwards (I think the idea is to keep them intact).

For the private space items, I cannot think of a better way unless we create some kind of action log - user mapping indicating the visibility of the item per user. But that seems cumbersome and quite a lot more work as well.

@leio10 leio10 merged commit ce0d79f into decidim:develop Jul 20, 2021
@ahukkanen ahukkanen deleted the fix/user-activity-pagination branch July 20, 2021 08:52
entantoencuanto added a commit that referenced this pull request Jul 26, 2021
* develop: (32 commits)
  Remove obsolete rake webpack task (#8237)
  Active storage migrations service (#7902)
  Fix content type delegation to blank attachments (#8230)
  Evote bug fixing (#8220)
  Fix the proposal data migration for proposals without authors or organization (#8015)
  Bump addressable version because security issues (#8229)
  Online meetings iframe visibility with time (#8097)
  Meetings iframe and iframe URL (#8096)
  Remove flaky test on meetings (#8226)
  Fix broken tests after problematic PRs (#8224)
  Apply permissions system to comments (#8035)
  Set current_component as commentable when commentable is a participatory space (#8189)
  Fix don't require inactive authorization handlers (#8122)
  Improve metrics calculations performance (#8215)
  Fix performance issue in notification settings page (#8155)
  Active storage migration (#7598)
  Update manual installation guide in documentation (#8217)
  Load JS configuration in elections focus mode layout (#8213)
  Fix user activity pagination when there are hidden items (#8202)
  Make it possible to define SCSS settings overrides from modules (#8198)
  ...
roxanaopr pushed a commit to i-need-another-coffee/decidim that referenced this pull request Jul 29, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

in-review module: core type: fix PRs that implement a fix for a bug

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants