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:
parent
d462abb5b5
commit
3a08716ad3
2 changed files with 1 additions and 12 deletions
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue