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

Fixing eager loading issue in admin/moderation/reports #19274

Merged
merged 4 commits into from Apr 12, 2023

Conversation

rt4914
Copy link
Contributor

@rt4914 rt4914 commented Mar 28, 2023

What type of PR is this? (check all applicable)

  • Bug Fix

Description

If we open http://localhost:3000/admin/moderation/reports in locally, it fails to load the page with following error:

00:58:04 web.1       | GET /admin/moderation/reports
00:58:04 web.1       | AVOID eager loading detected
00:58:04 web.1       |   FeedbackMessage => [:reporter]
00:58:04 web.1       |   Remove from your query: .includes([:reporter])
00:58:04 web.1       | Call stack
00:58:04 web.1       |   /forem/app/views/admin/feedback_messages/_feedback_message.html.erb:146:in `_app_views_admin_feedback_messages__feedback_message_html_erb___2929576808175770137_571260'
00:58:04 web.1       |  /forem/app/views/admin/feedback_messages/index.html.erb:34:in `block (2 levels) in _app_views_admin_feedback_messages_index_html_erb__3034821833808733872_570820'
00:58:04 web.1       |   /forem/app/views/admin/feedback_messages/index.html.erb:33:in `block in _app_views_admin_feedback_messages_index_html_erb__3034821833808733872_570820'
00:58:04 web.1       |   /forem/app/views/admin/feedback_messages/index.html.erb:32:in `_app_views_admin_feedback_messages_index_html_erb__3034821833808733872_570820'

This PR fixes this error by removing reporter from eager loading.

Related Tickets & Documents

  • None

QA Instructions, Screenshots, Recordings

Error + Solution Video: https://www.loom.com/share/600d4b029f8c49babe98d805a82bf78e

UI accessibility concerns?

No

Added/updated tests?

  • No

[Forem core team only] How will this change be communicated?

  • This change does not need to be communicated

@rt4914 rt4914 marked this pull request as ready for review March 28, 2023 19:32
@rt4914 rt4914 requested a review from a team as a code owner March 28, 2023 19:32
@rt4914 rt4914 requested review from lightalloy and lboogie04 and removed request for a team March 28, 2023 19:32
@codecov
Copy link

codecov bot commented Mar 28, 2023

Codecov Report

Patch coverage has no change and project coverage change: -0.01 ⚠️

Comparison is base (22250a3) 88.86% compared to head (5945c8d) 88.86%.

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #19274      +/-   ##
==========================================
- Coverage   88.86%   88.86%   -0.01%     
==========================================
  Files        1177     1177              
  Lines       26433    26433              
  Branches     2028     2028              
==========================================
- Hits        23491    23490       -1     
- Misses       2789     2790       +1     
  Partials      153      153              
Flag Coverage Δ
cypress 70.15% <ø> (ø)
javascript 76.39% <ø> (ø)
jest 46.30% <ø> (ø)
ruby 94.80% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

see 1 file with indirect coverage changes

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report in Codecov by Sentry.
📢 Do you have feedback about the report comment? Let us know in this issue.

@github-actions
Copy link
Contributor

github-actions bot commented Mar 28, 2023

Uffizzi Preview deployment-20581 was deleted.

@jaw6
Copy link
Contributor

jaw6 commented Mar 29, 2023

Any suggestions on how to QA this? I don't see bullet errors on main, so I'm thinking there might be a particular data scenario I would need to trigger it?

@lightalloy
Copy link
Contributor

I couldn't reproduce this error too, but checked the code: it's interesting that we do have refer to the feedback_message.reporter in this view:

<%= email_field_tag :reporter_email_to, feedback_message.reporter&.email, class: "crayons-textfield my-1", id: "reporter__emailto__#{feedback_message.id}", required: true %>

So, if we remove :reporter from includes and create a feedback message that has the reporter, then go to the described page, we'll get an error from bullet:

USE eager loading detected
  FeedbackMessage => [:reporter]
  Add to your query: .includes([:reporter])
Call stack
  /home/light/sites/dev.to/app/views/admin/feedback_messages/_feedback_message.html.erb:130:in `_app_views_admin_feedback_messages__feedback_message_html_erb___3216089565245649644_508000'

So, we can't just remove the includes. I'll look into this later and try to find why bullet could complain on this include

@lightalloy
Copy link
Contributor

I could reproduce (on another computer) on a main branch with this data:

=> [#<FeedbackMessage:0x000055c202980750
  id: 1,
  affected_id: nil,
  category: "spam",
  created_at: Thu, 25 Mar 2021 09:56:47.155902000 UTC +00:00,
  feedback_type: "spam",
  message: "Itaque tempore molestiae et.",
  offender_id: nil,
  reported_url: nil,
  reporter_id: 11,
  status: "Open",
  updated_at: Thu, 25 Mar 2021 09:56:47.155902000 UTC +00:00>,
 #<FeedbackMessage:0x00007eff7df6c3f8
  id: 2,
  affected_id: nil,
  category: "harassment",
  created_at: Thu, 25 Mar 2021 09:56:47.161301000 UTC +00:00,
  feedback_type: "abuse-reports",
  message: "Fugit qui dolores inventore.",
  offender_id: nil,
  reported_url: "example.com",
  reporter_id: 1,
  status: "Open",
  updated_at: Thu, 25 Mar 2021 09:56:47.161301000 UTC +00:00>]

Interestingly, these records have reporter_id, so we do use the loaded association.
Maybe it's related to the bullet issue

@rt4914
Copy link
Contributor Author

rt4914 commented Mar 30, 2023

Any suggestions on how to QA this? I don't see bullet errors on main, so I'm thinking there might be a particular data scenario I would need to trigger it?

@jaw6 I wasn't aware that it happened under certain scenarios only. I just had the fresh copy of the entire project and this error started. I think @lightalloy comments can help.

@lightalloy Thanks for detailed investigation.

@rt4914 rt4914 requested a review from jaw6 March 31, 2023 18:38
@jaw6
Copy link
Contributor

jaw6 commented Apr 3, 2023

I'm still having trouble replicating, despite having created many reports in my local environment. Still not sure what's up, but — just reading along — it does seem like we want this eager load more than we don't, @lightalloy is probably correct that this is a bullet bug.

@rt4914
Copy link
Contributor Author

rt4914 commented Apr 4, 2023

@jaw6 @lightalloy
Can you help in figuring out what can be the next steps here for me?

@jaw6
Copy link
Contributor

jaw6 commented Apr 5, 2023

@rt4914 I would recommend adding reporter to the bullet configuration here as (another) unused_eager_loading. It should be fairly straight-forward, but let me know if you want to pair on it, sometimes nice to have an extra set of eyes!

@@ -3,7 +3,7 @@ class FeedbackMessagesController < Admin::ApplicationController
layout "admin"

def index
@q = FeedbackMessage.includes(:reporter, :offender, :affected)
@q = FeedbackMessage.includes(:offender, :affected)
Copy link
Contributor

Choose a reason for hiding this comment

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

I mentioned this in a comment previously, but I think the system wants me to formally request changes, so... I think instead we should add reporter to the bullet configuration here as (another) unused_eager_loading.

It should be fairly straight-forward, but let me know if you want to pair on it, sometimes nice to have an extra set of eyes!

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 have applied this change. Thanks @jaw6 for clarification.

Bullet.add_safelist(type: :unused_eager_loading, class_name: "FeedbackMessage", association: :reporter)

@rt4914
Copy link
Contributor Author

rt4914 commented Apr 7, 2023

Thanks @jaw6 Will apply these changes on Monday.

@rt4914 rt4914 requested a review from a team as a code owner April 7, 2023 18:32
@rt4914 rt4914 requested review from klardotsh and jaw6 and removed request for a team April 7, 2023 18:32
@Zainahad19

This comment was marked as spam.

Copy link
Contributor

@klardotsh klardotsh left a comment

Choose a reason for hiding this comment

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

I don't have enough context to provide any meaningful review here, so I'm tagging myself out from review on this (or hoping that this comment-review fulfills GitHub's request for my comment).

@rt4914
Copy link
Contributor Author

rt4914 commented Apr 12, 2023

Hi @jaw6 Can you please review this PR now?

Copy link
Contributor

@jaw6 jaw6 left a comment

Choose a reason for hiding this comment

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

Looks good to me — though, I never experienced the bullet alert myself, so trusting that this does actually resolve the problem!

@rt4914 rt4914 merged commit 8c3f2c5 into main Apr 12, 2023
32 checks passed
@rt4914 rt4914 deleted the rt4914/removing-reports-from-eager-loading branch April 12, 2023 13:17
Ridhwana pushed a commit that referenced this pull request Apr 12, 2023
* Removed reports from eager loading

* Fixed the issue in a bit different way
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.

None yet

6 participants