app/models/user.rb
def tag_recommendations(allow_run=true)
    # Compute on the fly in case the cron hasn't run for a new user
    compute_recommendations if allow_run && newish_user && suggested_tags.count.zero?

    # Return hash of tag string => number of readable notebooks
    suggested = suggested_tags.pluck(:tag)
    counts = Notebook
      .readable_by(self)
      .joins('LEFT OUTER JOIN tags ON tags.notebook_id = notebooks.id')
      .where('tags.tag IN (?)', suggested)
      .group(:tag)
      .count
    suggested
      .map {|tag| [tag, counts.fetch(tag, 0)]}
      .reject {|_tag, count| count.zero?}
      .sort_by {|_tag, count| -count + rand}
  end
# Recommended tags with number of readable notebooks
Recommended tags with number of readable notebooks
Recommended tags with number of readable notebooks
def tag_recommendations(allow_run=true)
    compute_recommendations if allow_run && newish_user && suggested_tags.count.zero?
    suggested = suggested_tags.pluck(:tag)
    counts = Notebook
      .readable_by(self)
      .joins('LEFT OUTER JOIN tags ON tags.notebook_id = notebooks.id')
      .where('tags.tag IN (?)', suggested)
      .group(:tag)
      .count
    suggested
      .map {|tag| [tag, counts.fetch(tag, 0)]}
      .reject {|_tag, count| count.zero?}
      .sort_by {|_tag, count| -count + rand}
  end
def tag_recommendations ( allow_run = true ) compute_recommendations if allow_run && newish_user && suggested_tags . count . zero? suggested = suggested_tags . pluck ( :tag ) counts = Notebook . readable_by ( self ) . joins ( 'LEFT OUTER JOIN tags ON tags.notebook_id = notebooks.id' ) . where ( 'tags.tag IN (?)' , suggested ) . group ( :tag ) . count suggested . map { | tag | [ tag , counts . fetch ( tag , 0 ) ] } . reject { | _tag , count | count . zero? } . sort_by { | _tag , count | - count + rand } end
Recommended tags with number of readable notebooks
Recommended tags with number of readable notebooks
# Compute on the fly in case the cron hasn't run for a new user # Return hash of tag string => number of readable notebooks
allow_run