<commit_before># frozen_string_literal: true

class Settings::FeaturedTagsController < Settings::BaseController
  before_action :set_featured_tags, only: :index
  before_action :set_featured_tag, except: [:index, :create]
  before_action :set_recently_used_tags, only: :index

  def index
    @featured_tag = FeaturedTag.new
  end

  def create
    @featured_tag = CreateFeaturedTagService.new.call(current_account, featured_tag_params[:name], force: false)

    if @featured_tag.valid?
      redirect_to settings_featured_tags_path
    else
      set_featured_tags
      set_recently_used_tags

      render :index
    end
  end

  def destroy
    RemoveFeaturedTagWorker.perform_async(current_account.id, @featured_tag.id)
    redirect_to settings_featured_tags_path
  end

  private

  def set_featured_tag
    @featured_tag = current_account.featured_tags.find(params[:id])
  end

  def set_featured_tags
    @featured_tags = current_account.featured_tags.order(statuses_count: :desc).reject(&:new_record?)
  end

  def set_recently_used_tags
    @recently_used_tags = Tag.recently_used(current_account).where.not(id: @featured_tags.map(&:id)).limit(10)
  end

  def featured_tag_params
    params.require(:featured_tag).permit(:name)
  end<commit_msg>Change featured hashtag deletion to be done synchronously (#19590)<commit_after># frozen_string_literal: true

class Settings::FeaturedTagsController < Settings::BaseController
  before_action :set_featured_tags, only: :index
  before_action :set_featured_tag, except: [:index, :create]
  before_action :set_recently_used_tags, only: :index

  def index
    @featured_tag = FeaturedTag.new
  end

  def create
    @featured_tag = CreateFeaturedTagService.new.call(current_account, featured_tag_params[:name], force: false)

    if @featured_tag.valid?
      redirect_to settings_featured_tags_path
    else
      set_featured_tags
      set_recently_used_tags

      render :index
    end
  end

  def destroy
    RemoveFeaturedTagService.new.call(current_account, @featured_tag)
    redirect_to settings_featured_tags_path
  end

  private

  def set_featured_tag
    @featured_tag = current_account.featured_tags.find(params[:id])
  end

  def set_featured_tags
    @featured_tags = current_account.featured_tags.order(statuses_count: :desc).reject(&:new_record?)
  end

  def set_recently_used_tags
    @recently_used_tags = Tag.recently_used(current_account).where.not(id: @featured_tags.map(&:id)).limit(10)
  end

  def featured_tag_params
    params.require(:featured_tag).permit(:name)
  end
{'fraction_non_alphanumeric': 0.08062622309197652, 'fraction_numerical': 0.0035225048923679062, 'mean_word_length': 4.97196261682243, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4148224', 'n_tokens_mistral': 878, 'n_tokens_neox': 838, 'n_words': 149}