<commit_before><?php
class Kwf_Component_Events_UrlCache extends Kwf_Component_Events
{
    private $_orExpr;

    public function getListeners()
    {
        $ret = array();
        $ret[] = array(
            'event' => 'Kwf_Component_Event_Row_UpdatesFinished',
            'callback' => 'onRowUpdatesFinished'
        );
        $ret[] = array(
            'event' => 'Kwf_Component_Event_Page_RecursiveUrlChanged',
            'callback' => 'onPageRecursiveUrlChanged'
        );
        return $ret;
    }

    protected function _init()
    {
        parent::_init();
        $this->_orExpr = new Kwf_Model_Select_Expr_Or(array());
    }

    public function onRowUpdatesFinished(Kwf_Component_Event_Row_UpdatesFinished $event)
    {
        $select = new Kwf_Model_Select();
        $select->where($this->_orExpr);
        $rows = Kwf_Component_Cache::getInstance()->getModel('url')->export(Kwf_Model_Abstract::FORMAT_ARRAY, $select);
        foreach ($rows as $row) {
            $cacheId = 'url-'.$row['url'];
            Kwf_Cache_Simple::delete($cacheId);
        }
    }

    public function onPageRecursiveUrlChanged(Kwf_Component_Event_Page_RecursiveUrlChanged $event)
    {
        $this->_orExpr[] = new Kwf_Model_Select_Expr_Like('page_id', str_replace('_', '\\_', $event->componentId).'%');
    }
}
<commit_msg>only execute query when there is something to do<commit_after><?php
class Kwf_Component_Events_UrlCache extends Kwf_Component_Events
{
    private $_orExpr;

    public function getListeners()
    {
        $ret = array();
        $ret[] = array(
            'event' => 'Kwf_Component_Event_Row_UpdatesFinished',
            'callback' => 'onRowUpdatesFinished'
        );
        $ret[] = array(
            'event' => 'Kwf_Component_Event_Page_RecursiveUrlChanged',
            'callback' => 'onPageRecursiveUrlChanged'
        );
        return $ret;
    }

    protected function _init()
    {
        parent::_init();
        $this->_orExpr = new Kwf_Model_Select_Expr_Or(array());
    }

    public function onRowUpdatesFinished(Kwf_Component_Event_Row_UpdatesFinished $event)
    {
        if (count($this->_orExpr->getExpressions())) {
            $select = new Kwf_Model_Select();
            $select->where($this->_orExpr);
            $rows = Kwf_Component_Cache::getInstance()->getModel('url')->export(Kwf_Model_Abstract::FORMAT_ARRAY, $select);
            foreach ($rows as $row) {
                $cacheId = 'url-'.$row['url'];
                Kwf_Cache_Simple::delete($cacheId);
            }
        }
    }

    public function onPageRecursiveUrlChanged(Kwf_Component_Event_Page_RecursiveUrlChanged $event)
    {
        $this->_orExpr[] = new Kwf_Model_Select_Expr_Like('page_id', str_replace('_', '\\_', $event->componentId).'%');
    }
}

{'fraction_non_alphanumeric': 0.13082437275985664, 'fraction_numerical': 0.0, 'mean_word_length': 2.7869742198100407, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 27, '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': '5980409', 'n_tokens_mistral': 888, 'n_tokens_neox': 859, 'n_words': 130}