<commit_before>package com.nincraft.ninbot.components.config.component;

import lombok.val;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Repository
@Transactional
public class ComponentService {

    private ComponentRepository componentRepository;
    private DisabledComponentsRepository disabledComponentsRepository;

    public ComponentService(ComponentRepository componentRepository,
            DisabledComponentsRepository disabledComponentsRepository) {
        this.componentRepository = componentRepository;
        this.disabledComponentsRepository = disabledComponentsRepository;
    }

    public List<Component> getAllComponents() {
        return componentRepository.findAll();
    }

    public void registerComponent(String name, ComponentType componentType) {
        val componentOptional = componentRepository.findByNameAndType(name, componentType);
        if (!componentOptional.isPresent()) {
            Component component = new Component(name, componentType);
            componentRepository.save(component);
        }
    }

    void disableComponent(String name, String serverId) {
        val component = componentRepository.findByName(name);
        val list = disabledComponentsRepository.findByComponentAndServerId(component, serverId);
        if (list.isEmpty()) {
            DisabledComponents disabledComponents = new DisabledComponents(serverId, component);
            disabledComponentsRepository.save(disabledComponents);
        }
    }

    private List<DisabledComponents> getDisabledComponents(Component component, String serverId) {
        return disabledComponentsRepository.findByComponentAndServerId(component, serverId);
    }

    @Cacheable("disabled-component")
    public boolean isDisabled(String name, String serverId) {
        val component = componentRepository.findByName(name);
        return !getDisabledComponents(component, serverId).isEmpty();
    }

    void enableComponent(String name, String serverId) {
        val component = componentRepository.findByName(name);
        getDisabledComponents(component, serverId).forEach(disabledComponents ->
                disabledComponentsRepository.delete(disabledComponents));
    }

    @Cacheable("disabled-server-component")
    public List<DisabledComponents> getDisabledComponents(String serverId) {<commit_msg>Fix component cache issue<commit_after>package com.nincraft.ninbot.components.config.component;

import lombok.val;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Repository
@Transactional
public class ComponentService {

    private ComponentRepository componentRepository;
    private DisabledComponentsRepository disabledComponentsRepository;

    public ComponentService(ComponentRepository componentRepository,
            DisabledComponentsRepository disabledComponentsRepository) {
        this.componentRepository = componentRepository;
        this.disabledComponentsRepository = disabledComponentsRepository;
    }

    public List<Component> getAllComponents() {
        return componentRepository.findAll();
    }

    public void registerComponent(String name, ComponentType componentType) {
        val componentOptional = componentRepository.findByNameAndType(name, componentType);
        if (!componentOptional.isPresent()) {
            Component component = new Component(name, componentType);
            componentRepository.save(component);
        }
    }

    @CacheEvict(allEntries = true, value = {"disable-component", "disabled-server-component"})
    public void disableComponent(String name, String serverId) {
        val component = componentRepository.findByName(name);
        val list = disabledComponentsRepository.findByComponentAndServerId(component, serverId);
        if (list.isEmpty()) {
            DisabledComponents disabledComponents = new DisabledComponents(serverId, component);
            disabledComponentsRepository.save(disabledComponents);
        }
    }

    private List<DisabledComponents> getDisabledComponents(Component component, String serverId) {
        return disabledComponentsRepository.findByComponentAndServerId(component, serverId);
    }

    @Cacheable("disabled-component")
    public boolean isDisabled(String name, String serverId) {
        val component = componentRepository.findByName(name);
        return !getDisabledComponents(component, serverId).isEmpty();
    }

    void enableComponent(String name, String serverId) {
        val component = componentRepository.findByName(name);
        getDisabledComponents(component, serverId).forEach(disabledComponents ->
                disabledComponentsRepository.delete(disabledComponents));
    }

    @Cacheable("disabled-server-component")
    public List<DisabledComponents> getDisabledComponents(String serverId) {
{'fraction_non_alphanumeric': 0.07576938059992208, 'fraction_numerical': 0.0, 'mean_word_length': 4.37696335078534, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 11, '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': '1569542', 'n_tokens_mistral': 1136, 'n_tokens_neox': 1118, 'n_words': 237}