Skip to content

Commit

Permalink
[api][webui] Refactor cleanup of notifications to use offset instead …
Browse files Browse the repository at this point in the history
…of slice
  • Loading branch information
Moises Deniz Aleman authored and hennevogel committed Jun 29, 2017
1 parent b86aa65 commit 0520e67
Showing 1 changed file with 4 additions and 7 deletions.
11 changes: 4 additions & 7 deletions src/api/app/models/notifications/rss_feed_item.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,14 @@ class Notifications::RssFeedItem < Notifications::Base
def self.cleanup
User.all_without_nobody.find_in_batches batch_size: 500 do |batch|
batch.each do |user|
if user.is_active?
ids = user.rss_feed_items.pluck(:id).slice(MAX_ITEMS_PER_USER..-1)
user.rss_feed_items.where(id: ids).delete_all
else
user.rss_feed_items.delete_all
end
offset = user.is_active? ? MAX_ITEMS_PER_USER : 0
ids = user.rss_feed_items.offset(offset).pluck(:id)
user.rss_feed_items.where(id: ids).delete_all
end
end
Group.find_in_batches batch_size: 500 do |batch|
batch.each do |group|
ids = group.rss_feed_items.pluck(:id).slice(MAX_ITEMS_PER_GROUP..-1)
ids = group.rss_feed_items.offset(MAX_ITEMS_PER_GROUP).pluck(:id)
group.rss_feed_items.where(id: ids).delete_all
end
end
Expand Down

0 comments on commit 0520e67

Please sign in to comment.