Files
danbooru/app/logical/curated_pool_updater.rb
evazion aaab527baa Move Curated pool updater to Danbooru.
* Move the Curated pool updater from Reportbooru to Danbooru.

* Change the process for selecting curated posts. Previously it was
  every post from the last week with at least three supervotes. This was
  flawed because it included both super-upvotes and super-downvotes. Now
  it's the top 100 posts from the last week, ordered from most super-upvoted
  to least.
2019-11-23 18:19:08 -06:00

17 lines
577 B
Ruby

module CuratedPoolUpdater
def self.curated_posts(date_range: (1.week.ago..Time.now), limit: 100)
posts = Post.where(created_at: date_range)
posts = posts.joins(:votes).where("post_votes.score": SuperVoter::MAGNITUDE)
posts = Post.where(id: posts.group(:id).order(Arel.sql("COUNT(*) DESC")).limit(limit))
posts
end
def self.update_pool!(pool_id = Danbooru.config.curated_pool_id)
return unless pool_id.present?
CurrentUser.scoped(User.system, "127.0.0.1") do
Pool.find(pool_id).update!(post_ids: curated_posts.pluck(:id))
end
end
end