app/models/user.rb
# Recommended groups with number of readable notebooks
Recommended groups with number of readable notebooks
Recommended groups with number of readable notebooks
def group_recommendations(allow_run=true)
    compute_recommendations if allow_run && newish_user && suggested_groups.count.zero?
    suggested = Group.find(suggested_groups.pluck(:group_id))
    counts = Notebook.readable_by(self).where(owner: suggested).group(:owner_id).count
    suggested
      .map {|group| [group, counts.fetch(group.id, 0)]}
      .reject {|_group, count| count.zero?}
      .sort_by {|_group, count| -count + rand}
  end
def group_recommendations ( allow_run = true ) compute_recommendations if allow_run && newish_user && suggested_groups . count . zero? suggested = Group . find ( suggested_groups . pluck ( :group_id ) ) counts = Notebook . readable_by ( self ) . where ( owner : suggested ) . group ( :owner_id ) . count suggested . map { | group | [ group , counts . fetch ( group . id , 0 ) ] } . reject { | _group , count | count . zero? } . sort_by { | _group , count | - count + rand } end
Recommended groups with number of readable notebooks
Recommended groups with number of readable notebooks
# Compute on the fly in case the cron hasn't run for a new user # Return hash of Group objects => number of readable notebooks
allow_run