docbrown/app/workers/users/resave_articles_worker.rb
Jeremy Friesen 3a08716ad3
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
2022-04-01 13:32:44 -04:00

14 lines
297 B
Ruby

module Users
class ResaveArticlesWorker
include Sidekiq::Worker
sidekiq_options queue: :medium_priority, retry: 10, lock: :until_executing
def perform(user_id)
user = User.find_by(id: user_id)
return unless user
user.articles.find_each(&:save)
end
end
end