Files
danbooru/app/controllers/recommended_posts_controller.rb
evazion fa985f08ab recommendations: filter out own uploads and favorites.
Filter out the user's own uploads and favorites from their
recommendations.

Note that in most cases a user's top-N recommendations will be things
they've already favorited. If a user has 10,000 favorites, most of their
top 10,000 recommendations will be their own favorites, so we have to
generate a little more than 10,000 recommendations to be sure they won't
all be filtered out.

In other words, the more favorites a user has, the more recommendations
we have to generate. The upper bound is clamped to 50,000 for
performance reasons. If a user has more favorites than this we may not
be able to find any recommendations for them.
2019-12-01 19:03:26 -06:00

12 lines
300 B
Ruby

class RecommendedPostsController < ApplicationController
respond_to :html, :json, :xml, :js
def show
limit = params.fetch(:limit, 100).to_i.clamp(0, 200)
@recs = RecommenderService.search(params).take(limit)
@posts = @recs.map { |rec| rec[:post] }
respond_with(@recs)
end
end