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

Ensuring article's cache updates on org image update #17052

Merged
merged 1 commit into from Apr 1, 2022

Conversation

jeremyf
Copy link
Contributor

@jeremyf jeremyf commented Mar 30, 2022

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

  • Refactor
  • Bug Fix
  • Optimization
  • Documentation Update

Description

There are three major things occurring in this pull request:

  1. Renaming Article#update_cached_user to Article#set_cached_entities.
  2. Reducing an organization's direct knowledge of which of the org's
    attributes an article caches.
  3. Removing duplicate calls to update the article associated with the
    organization.

For renaming to Article#set_cached_entities, the prior method implied
we were updating the persistence layer. However, we were not making any
save nor update calls. This rename should clarify intention.

For reducing knowledge, the comments for
Article::ATTRIBUTES_CACHED_FOR_RELATED_ENTITY should explain the details.

And last, removing the duplicate calls; we had three methods that were
attempting to build and update the Article#cached_organization's
value.

Related Tickets & Documents

Closes #17041

QA Instructions, Screenshots, Recordings

My hope is that the tests cover this. To test via the UI, I leave the
following gherkin as guide:

Go to / and make sure that there's an article with an organization.

Given an article A that is associated with organization B.
When I update the organization B's image.
Then article A's organization image reflects the new image for B.

Now, after the change, look on the dashboard for that article's organization
image. It should have changed.

UI accessibility concerns?

None.

Added/updated tests?

  • Yes

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

  • I will share this change internally with the appropriate teams

There are three major things occurring in this pull request:

1. Renaming `Article#update_cached_user` to `Article#set_cached_entities`.
2. Reducing an organization's direct knowledge of which of the org's
   attributes an article caches.
3. Removing duplicate calls to update the article associated with the
   organization.

For renaming to `Article#set_cached_entities`, the prior method implied
we were updating the persistence layer.  However, we were not making any
save nor update calls.  This rename should clarify intention.

For reducing knowledge, the comments for
`Article::ATTRIBUTES_CACHED_FOR_RELATED_ENTITY` should explain the details.

And last, removing the duplicate calls; we had three methods that were
attempting to build and update the `Article#cached_organization`'s
value.

Closes #17041
@jeremyf jeremyf requested a review from a team March 30, 2022 12:43
@pr-triage pr-triage bot added the PR: unreviewed bot applied label for PR's with no review label Mar 30, 2022
jeremyf added a commit to forem/forem-docs that referenced this pull request Mar 30, 2022
Copy link
Contributor

@djuber djuber left a comment

Choose a reason for hiding this comment

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

I have almost certainly had the same struggles with carrierwave interaction on existing models.

return unless saved_change_to_attribute?(:name)

articles.update(cached_organization: Articles::CachedEntity.from_object(self))
articles.each(&:save)
Copy link
Contributor

Choose a reason for hiding this comment

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

this makes sense given the hook is now "before save". Saving will trigger the expected action.

also, the TODO comment earlier suggested a lot of the existing complication was related to pushing search documents into ES (and we don't do that any more).

@pr-triage pr-triage bot added PR: partially-approved bot applied label for PR's where a single reviewer approves changes and removed PR: unreviewed bot applied label for PR's with no review labels Mar 30, 2022
@jeremyf jeremyf requested a review from a team March 30, 2022 17:47
@jeremyf
Copy link
Contributor Author

jeremyf commented Mar 30, 2022

Confession time, I spent hours 10pm to 11pm fighting with the carrier wave issue. And then from hours 11pm to 7am, as I slept my brain noodled on this. At 8am I said "Alright, let's try a new instance of the object to see if that works."

And lo' it did.

Copy link
Contributor

@msarit msarit left a comment

Choose a reason for hiding this comment

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

Works like a dream! 🌤️

@pr-triage pr-triage bot added PR: reviewed-approved bot applied label for PR's where reviewer approves changes and removed PR: partially-approved bot applied label for PR's where a single reviewer approves changes labels Apr 1, 2022
@jeremyf jeremyf merged commit d462abb into main Apr 1, 2022
@jeremyf jeremyf deleted the jeremyf/take-3-for-issue---forem/forem#17041 branch April 1, 2022 14:54
@pr-triage pr-triage bot added PR: merged bot applied label for PR's that are merged and removed PR: reviewed-approved bot applied label for PR's where reviewer approves changes labels Apr 1, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
PR: merged bot applied label for PR's that are merged
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Changing an organization's image should invalidate the associated articles cached organization
3 participants