fix: Revert the changes for SyncCustomFilterCountJob (#8238)

This commit is contained in:
Pranav Raj S
2023-10-27 10:45:48 -07:00
committed by GitHub
parent f023325b0e
commit 6c4b92f7f6
6 changed files with 0 additions and 59 deletions

View File

@@ -1,9 +0,0 @@
class CustomFiltersRecordsCountUpdateJob < ApplicationJob
queue_as :low
def perform
CustomFilter.find_each(batch_size: 25) do |filter|
SyncCustomFilterCountJob.perform_later(filter)
end
end
end

View File

@@ -1,9 +0,0 @@
class SyncCustomFilterCountJob < ApplicationJob
queue_as :low
def perform(filter)
Redis::Alfred.set(filter.filter_count_key, 0) if filter.filter_records.nil?
filter.set_record_count_in_redis
end
end

View File

@@ -24,29 +24,6 @@ class CustomFilter < ApplicationRecord
enum filter_type: { conversation: 0, contact: 1, report: 2 }
validate :validate_number_of_filters
def records_count
fetch_record_count_from_redis
end
def filter_records
Conversations::FilterService.new(query.with_indifferent_access, user, account).perform
end
def set_record_count_in_redis
records = filter_records
Redis::Alfred.set(filter_count_key, records[:count][:all_count])
end
def fetch_record_count_from_redis
number_of_records = Redis::Alfred.get(filter_count_key)
SyncCustomFilterCountJob.perform_later(self) if number_of_records.nil?
number_of_records.to_i
end
def filter_count_key
format(::Redis::Alfred::CUSTOM_FILTER_RECORDS_COUNT_KEY, account_id: account_id, filter_id: id, user_id: user_id)
end
def validate_number_of_filters
return true if account.custom_filters.where(user_id: user_id).size < MAX_FILTER_PER_USER

View File

@@ -4,4 +4,3 @@ json.filter_type resource.filter_type
json.query resource.query
json.created_at resource.created_at
json.updated_at resource.updated_at
json.count resource.records_count

View File

@@ -31,7 +31,6 @@ module Redis::RedisKeys
LATEST_CHATWOOT_VERSION = 'LATEST_CHATWOOT_VERSION'.freeze
# Check if a message create with same source-id is in progress?
MESSAGE_SOURCE_KEY = 'MESSAGE_SOURCE_KEY::%<id>s'.freeze
CUSTOM_FILTER_RECORDS_COUNT_KEY = 'CUSTOM_FILTER::%<account_id>d::%<user_id>d::%<filter_id>d'.freeze
OPENAI_CONVERSATION_KEY = 'OPEN_AI_CONVERSATION_KEY::%<event_name>s::%<conversation_id>d::%<updated_at>d'.freeze
## Sempahores / Locks

View File

@@ -41,17 +41,6 @@ RSpec.describe 'Custom Filters API', type: :request do
expect(response_body.first['name']).to eq(custom_filter.name)
expect(response_body.first['query']).to eq(custom_filter.query)
end
it 'returns custom_filter conversations count when set in redis' do
get "/api/v1/accounts/#{account.id}/custom_filters",
headers: user.create_new_auth_token,
as: :json
expect(response).to have_http_status(:success)
response_body = response.parsed_body
expect(response_body.first['name']).to eq(custom_filter.name)
expect(response_body.first['count']).to eq(custom_filter.fetch_record_count_from_redis)
end
end
end
@@ -66,16 +55,12 @@ RSpec.describe 'Custom Filters API', type: :request do
context 'when it is an authenticated user' do
it 'shows the custom filter' do
custom_filter.set_record_count_in_redis
get "/api/v1/accounts/#{account.id}/custom_filters/#{custom_filter.id}",
headers: user.create_new_auth_token,
as: :json
expect(response).to have_http_status(:success)
expect(response.body).to include(custom_filter.name)
json_response = response.parsed_body
expect(json_response['count']).to eq 1
end
end
end
@@ -106,7 +91,6 @@ RSpec.describe 'Custom Filters API', type: :request do
expect(response).to have_http_status(:success)
json_response = response.parsed_body
expect(json_response['name']).to eq 'vip-customers'
expect(json_response['count']).to be_zero
end
it 'gives the error for 51st record' do