Reducing subtle duplication of effort/logic (#17078)

Prior to this commit, when we change attributes for a user we might
resave each article.  The purpose of the resave is to update some of the
cached attributes of an article.

This removes some redundant code.  The following removed code has
an `article.save` call.  Which, the callbacks in the article (see below)
already clear the cache.

```ruby
def resave_articles
  articles.find_each do |article|
    if article.path
      cache_bust = EdgeCache::Bust.new
      cache_bust.call(article.path)
      cache_bust.call("#{article.path}?i=i")
    end
    article.save
  end
end
```

8e6981aac5/app/models/article.rb (L164)

8e6981aac5/app/models/article.rb (L881-L888)

This was discovered in triaging forem/forem#17041
This commit is contained in:
Jeremy Friesen 2022-04-01 13:32:44 -04:00 committed by GitHub
parent d462abb5b5
commit 3a08716ad3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 1 additions and 12 deletions

View file

@ -497,17 +497,6 @@ class User < ApplicationRecord
monthly_dues.positive?
end
def resave_articles
articles.find_each do |article|
if article.path
cache_bust = EdgeCache::Bust.new
cache_bust.call(article.path)
cache_bust.call("#{article.path}?i=i")
end
article.save
end
end
def profile_image_90
profile_image_url_for(length: 90)
end

View file

@ -8,7 +8,7 @@ module Users
user = User.find_by(id: user_id)
return unless user
user.resave_articles
user.articles.find_each(&:save)
end
end
end