From e159217dcea43a5d706e47b6238e1e680c7294d3 Mon Sep 17 00:00:00 2001 From: Molly Struve Date: Fri, 7 Feb 2020 12:39:59 -0500 Subject: [PATCH] Remove Unused ChatChannel Indexing (#5907) [deploy] * remove unused algolia code from chat channel * remove new chat_channel index code and unused methods --- .../chat_channel_memberships_controller.rb | 3 --- app/controllers/chat_channels_controller.rb | 1 - app/models/chat_channel.rb | 23 ------------------- app/models/message.rb | 1 - app/services/users/cleanup_chat_channels.rb | 1 - 5 files changed, 29 deletions(-) diff --git a/app/controllers/chat_channel_memberships_controller.rb b/app/controllers/chat_channel_memberships_controller.rb index 6aac18e5f..b57d22498 100644 --- a/app/controllers/chat_channel_memberships_controller.rb +++ b/app/controllers/chat_channel_memberships_controller.rb @@ -19,7 +19,6 @@ class ChatChannelMembershipsController < ApplicationController chat_channel_id: @chat_channel.id, status: "pending", ) - @chat_channel.index! end def update @@ -31,7 +30,6 @@ class ChatChannelMembershipsController < ApplicationController else @chat_channel_membership.update(status: "rejected") end - @chat_channel_membership.chat_channel.index! @chat_channels_memberships = current_user. chat_channel_memberships.includes(:chat_channel). where(status: "pending"). @@ -45,7 +43,6 @@ class ChatChannelMembershipsController < ApplicationController authorize @chat_channel_membership @chat_channel_membership.update(status: "left_channel") @chat_channel_membership.remove_from_index! - @chat_channel_membership.chat_channel.index! @chat_channels_memberships = [] render json: { result: "left channel" }, status: :created end diff --git a/app/controllers/chat_channels_controller.rb b/app/controllers/chat_channels_controller.rb index 5d44c75eb..5dece12ad 100644 --- a/app/controllers/chat_channels_controller.rb +++ b/app/controllers/chat_channels_controller.rb @@ -38,7 +38,6 @@ class ChatChannelsController < ApplicationController membership = @chat_channel.chat_channel_memberships.where(user_id: current_user.id).first membership.update(last_opened_at: 1.second.from_now, has_unopened_messages: false) send_open_notification - @chat_channel.index! membership.index! render json: { status: "success", channel: params[:id] }, status: :ok end diff --git a/app/models/chat_channel.rb b/app/models/chat_channel.rb index c233d3332..e8c4066ec 100644 --- a/app/models/chat_channel.rb +++ b/app/models/chat_channel.rb @@ -1,5 +1,4 @@ class ChatChannel < ApplicationRecord - include AlgoliaSearch attr_accessor :current_user, :usernames_string has_many :messages, dependent: :destroy @@ -19,18 +18,6 @@ class ChatChannel < ApplicationRecord validates :status, presence: true, inclusion: { in: %w[active inactive blocked] } validates :slug, uniqueness: true, presence: true - algoliasearch index_name: "SecuredChatChannel_#{Rails.env}" do - attribute :id, :viewable_by, :slug, :channel_type, - :channel_name, :last_message_at, :status, - :messages_count, :channel_human_names, :channel_mod_ids, :pending_users_select_fields, - :description - searchableAttributes %i[channel_name channel_slug channel_human_names] - attributesForFaceting ["filterOnly(viewable_by)", "filterOnly(status)", "filterOnly(channel_type)"] - ranking ["desc(last_message_at)"] - end - - before_destroy :remove_from_index!, prepend: true - def open? channel_type == "open" end @@ -90,7 +77,6 @@ class ChatChannel < ApplicationRecord status: "active", ) channel.add_users(users) - channel.index! channel.chat_channel_memberships.map(&:index!) end channel @@ -131,14 +117,6 @@ class ChatChannel < ApplicationRecord end end - def viewable_by - active_memberships.pluck(:user_id) - end - - def messages_count - messages.size - end - def channel_human_names active_memberships. order("last_opened_at DESC").limit(5).includes(:user).map do |membership| @@ -147,7 +125,6 @@ class ChatChannel < ApplicationRecord end def channel_users - # Purely for algolia indexing obj = {} relation = active_memberships.includes(:user).select(:id, :user_id, :last_opened_at) diff --git a/app/models/message.rb b/app/models/message.rb index e5790024d..7de20f45e 100644 --- a/app/models/message.rb +++ b/app/models/message.rb @@ -27,7 +27,6 @@ class Message < ApplicationRecord def update_chat_channel_last_message_at chat_channel.touch(:last_message_at) - chat_channel.index! chat_channel.chat_channel_memberships.reindex! end diff --git a/app/services/users/cleanup_chat_channels.rb b/app/services/users/cleanup_chat_channels.rb index 72fb61d32..4e9cb480f 100644 --- a/app/services/users/cleanup_chat_channels.rb +++ b/app/services/users/cleanup_chat_channels.rb @@ -4,7 +4,6 @@ module Users # We only destroy direct message channels, not open and invite-only ones direct_channels = user.chat_channels.where(channel_type: "direct") direct_channels.each do |direct_channel| - direct_channel.remove_from_index! cleanup_memberships(direct_channel.chat_channel_memberships) direct_channel.destroy! end