[deploy] Remove Algolia from User Model (#7454)

* Remove Algolia from User Model

* check banned on self for user

* fine have your redundant method

* remove a couple more unnecessary specs
This commit is contained in:
Molly Struve 2020-04-24 17:39:36 -05:00 committed by GitHub
parent 94f3a4b6fd
commit a7e664fc9c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 2 additions and 114 deletions

View file

@ -1,5 +1,4 @@
class User < ApplicationRecord
include AlgoliaSearch
include CloudinaryHelper
include Searchable
include Storext.model
@ -162,7 +161,6 @@ class User < ApplicationRecord
before_validation :set_config_input
before_validation :downcase_email
before_validation :check_for_username_change
before_destroy :remove_from_algolia_index, prepend: true
before_destroy :destroy_empty_dm_channels, prepend: true
before_destroy :destroy_follows, prepend: true
before_destroy :unsubscribe_from_newsletters, prepend: true
@ -172,43 +170,6 @@ class User < ApplicationRecord
after_commit :sync_related_elasticsearch_docs, on: %i[create update]
after_commit :remove_from_elasticsearch, on: [:destroy]
algoliasearch per_environment: true, enqueue: :trigger_delayed_index do
attribute :name
add_index "searchables",
id: :index_id,
per_environment: true,
enqueue: true do
attribute :user do
{
username: user.username,
name: user.username,
profile_image_90: profile_image_90,
pro: user.pro?
}
end
attribute :title, :path, :tag_list, :main_image, :id,
:featured, :published, :published_at, :featured_number, :comments_count,
:reactions_count, :positive_reactions_count, :class_name, :user_name,
:user_username, :comments_blob, :body_text, :tag_keywords_for_search,
:search_score, :hotness_score
searchableAttributes ["unordered(title)",
"body_text",
"tag_list",
"tag_keywords_for_search",
"user_name",
"user_username",
"comments_blob"]
attributesForFaceting [:class_name]
customRanking ["desc(search_score)", "desc(hotness_score)"]
end
end
def self.trigger_delayed_index(record, remove)
return if remove
Search::IndexWorker.perform_async("User", record.id)
end
def self.dev_account
find_by(id: SiteConfig.staff_user_id)
end
@ -449,11 +410,6 @@ class User < ApplicationRecord
ProfileImage.new(self).get(width: 90)
end
def remove_from_algolia_index
remove_from_index!
Search::RemoveFromIndexWorker.perform_async("searchables_#{Rails.env}", index_id)
end
def unsubscribe_from_newsletters
return if email.blank?
@ -485,20 +441,12 @@ class User < ApplicationRecord
email_follower_notifications
end
def title
name
end
def hotness_score
search_score
end
private
def index_id
"users-#{id}"
end
def estimate_default_language
Users::EstimateDefaultLanguageWorker.perform_async(id)
end
@ -580,7 +528,7 @@ class User < ApplicationRecord
end
def conditionally_resave_articles
Users::ResaveArticlesWorker.perform_async(id) if core_profile_details_changed? && !user.banned
Users::ResaveArticlesWorker.perform_async(id) if core_profile_details_changed? && !banned
end
def bust_cache
@ -623,48 +571,11 @@ class User < ApplicationRecord
errors.add(:mastodon_url, "is not a valid URL")
end
def tag_list
"" # Unused but necessary for search index
end
def main_image; end
def featured
true
end
def published
true
end
def published_at; end
def featured_number; end
# TODO: @practicaldev/sre: Remove this redundant method
def user
self
end
def class_name
self.class.name
end
def user_name
username
end
def user_username
username
end
def comments_blob
"" # Unused but necessary for search index
end
def body_text
"" # Unused but necessary for search index
end
def tag_keywords_for_search
employer_name.to_s + mostly_work_with.to_s + available_for.to_s
end

View file

@ -20,7 +20,6 @@ module Moderator
delete_comments
delete_articles
Users::CleanupChatChannels.call(user)
user.remove_from_algolia_index
reassign_and_bust_username
delete_vomit_reactions
end

View file

@ -31,8 +31,6 @@ num_users = 10 * SEEDS_MULTIPLIER
counter += 1
Rails.logger.info "#{counter}. Creating #{num_users} Users"
User.clear_index!
roles = %i[trusted chatroom_beta_tester workshop_pass]
num_users.times do |i|

View file

@ -789,26 +789,6 @@ RSpec.describe User, type: :model do
end
end
context "when indexing and deindexing" do
it "triggers background auto-indexing when user is saved" do
sidekiq_assert_enqueued_with(job: Search::IndexWorker, args: ["User", user.id]) do
user.save
end
end
it "doesn't enqueue a job on destroy" do
user = build(:user)
sidekiq_perform_enqueued_jobs do
user.save
end
sidekiq_assert_no_enqueued_jobs(only: Search::IndexWorker) do
user.destroy
end
end
end
describe "user registration" do
let(:user) { create(:user) }