Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add caching to profanity filter route #35709

Merged
merged 3 commits into from
Jul 9, 2020
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 8 additions & 6 deletions dashboard/app/controllers/profanity_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,15 @@ class ProfanityController < ApplicationController
# @returns [Array<String>|nil] Profane words within the given string
def find
profanity_result = []
if params[:should_cache]
cache_key = "profanity/#{params[:language] || request.locale}/#{params[:text] || ''}"
profanity_result = Rails.cache.fetch(cache_key) do
ProfanityFilter.find_potential_profanities(params[:text] || "", params[:language] || request.locale)
unless params[:text].nil?
if params[:should_cache]
cache_key = "profanity/#{params[:language] || request.locale}/#{params[:text] || ''}"
JillianK marked this conversation as resolved.
Show resolved Hide resolved
profanity_result = Rails.cache.fetch(cache_key) do
JillianK marked this conversation as resolved.
Show resolved Hide resolved
ProfanityFilter.find_potential_profanities(params[:text], params[:language] || request.locale)
end
else
profanity_result = ProfanityFilter.find_potential_profanities(params[:text], params[:language] || request.locale)
end
else
profanity_result = ProfanityFilter.find_potential_profanities(params[:text] || "", params[:language] || request.locale)
end
render json: profanity_result
end
Expand Down