docbrown/app/services/users/suggest_for_sidebar.rb
Michael Kohl 1ebec4b67f
Remove hardcoded user profile fields (#14079)
* Remove duplicated work display from header

* Update work profile field handling

* Update DUS + spec

* Delegate more carefully

* Update delegation guard

* Adapt for removed delegation

* Undo accidental schema changes

* Fix seeds

* Remove accidentaly change

* Fix User#processed_website_url

* Update guard clause

* Update profile card content

* Add Organization#profile

* Be more conservative with profile fields

* Spec fixes round 1

* Fix typo

* Update spec

* Limit number of header fields and update card content

* Decorate correct model

* Update factory

* Update schema.rb

* Fix validation

* How bad could this possibly be?

* Pretty bad, nevermind

* Remove obsolete code

* Reset profile fields during test runs

* Move profile fields back to before(:suite)

* Spec fixes

* Remove accidentally re-added files

* More spec fixes

* Specs

* Change User#tag_keywords_for_search

* More spec fixes

* Add comment

* Undo accidental schema changes

* Attempt spec fix

* Remove fix attempt

* Fix e2e test

* Update spec

* Remove guard clause

* Remove hardcoded instances of education field

* WIP Access display_email_on_profile via User Settings

* Remove unused profile column

* WIP fix issues revealed by systems specs

* WIP fix issues revealed by services specs

* WIP Fix failing tests

* WIP Fix spec failures

* wip

* Move two attributes from controller to decorator

* Update comment

* More consistently use user.tag_line

Even before the profile changes we sometimes used the user.summary
attribute directly but used the user.tag_line method in other places.

* Remove education

* Add comment

* WIP

* Clean up mostly_work_with

* WIP

* Update work profile field handling

* More work-related changes

* Remove settings_only from display_area enum

* Remove quickfix from _metadata partial

* Remove special attributes

* Remove leftover spec

* Retrieve location from profile, not user

* Profile.special_attributes no longer exists

* Update specs

* More spec fixes

* Update UsersController

* Update UsersController and spec

* Fix e2e seeds

* Minor cleanup

* More e2e seed fixes

* Fix profile field CSV

* Fix e2e seeds

* Move one more attribute in e2e seeds

* Remove duplicate line

* Clear inputs before typing in them

Co-authored-by: Jacob Herrington <jacobherringtondeveloper@gmail.com>
2021-08-18 11:44:53 +07:00

47 lines
1.5 KiB
Ruby

module Users
class SuggestForSidebar
def self.call(user, given_tag)
new(user, given_tag).suggest
end
def initialize(user, given_tag)
@user = user
@given_tag = given_tag
# TODO: @citizen428 - I just moved this code from elsewhere, but 25 seems
# to be geared towards DEV and may not work for smaller communities.
@minimum_reaction_count = Rails.env.production? ? 25 : 0
end
def suggest
suggested_user_ids = Rails.cache.fetch(generate_cache_name, expires_in: 120.hours) do
(reputable_user_ids + random_user_ids).uniq
end
User.select(:id, :name, :username, :profile_image).where(id: suggested_user_ids)
end
private
attr_reader :user, :given_tag, :minimum_reaction_count
def generate_cache_name
"tag-#{given_tag}-user-#{user.id}-#{user.last_followed_at}/tag-follow-suggestions"
end
def active_authors_for_given_tags
@active_authors_for_given_tags ||= Article.published.tagged_with([given_tag], any: true)
.where(public_reactions_count: minimum_reaction_count..)
.where(published_at: 4.months.ago..)
.where.not(user_id: user.id)
.where.not(user_id: user.following_by_type("User"))
.pluck(:user_id)
end
def reputable_user_ids
User.where(id: active_authors_for_given_tags).order(reputation_modifier: :desc).limit(20).ids
end
def random_user_ids
User.where(id: active_authors_for_given_tags).order(Arel.sql("RANDOM()")).limit(20).ids
end
end
end