<commit_before><?php

class SV_ReportImprovements_Deferred_Upgrade_1090200 extends XenForo_Deferred_Abstract
{
    public function execute(array $deferred, array $data, $targetRunTime, &$status)
    {
        $increment = 250;
        $minCommentId = isset($data['comment_id']) ? $data['comment_id'] : -1;

        $db = XenForo_Application::getDb();

        $commentQuery = $db->query(
            "
            SELECT MAX(report_comment_id) AS max_report_comment_id
            FROM xf_report_comment 
            WHERE message LIKE '%http%'
            AND report_comment_id > ?
        ", [$minCommentId]
        );
        $commentRows = $commentQuery->fetchAll();

        if (empty($commentRows) || empty($commentRows[0]) || empty($commentRows[0]['max_report_comment_id']))
        {
            return false;
        }

        $commentQuery = $db->query(
            "
            SELECT report_comment_id, message
            FROM xf_report_comment 
            WHERE message LIKE '%http%'
            AND report_comment_id > ?
            ORDER BY report_comment_id
            LIMIT ?
        ", [$minCommentId, $increment]
        );

        $lastCommentId = false;
        $comments = $commentQuery->fetchAll();
        $s = microtime(true);

        if (!empty($comments))
        {
            foreach ($comments AS $comment)
            {
                $output = XenForo_Helper_String::autoLinkBbCode($comment['message']);
                if ($output !== null && $output != $comment['message'])
                {
                    $db->query(
                        '
                        UPDATE xf_report_comment
                        SET message = ?
                        WHERE report_comment_id = ?
                    ', [$output, $comment['report_comment_id']]
                    );
                }
                $lastCommentId = $comment['report_comment_id'];

                if ($targetRunTime && microtime(true) - $s > $targetRunTime)
                {
                    break;
                }
            }
        }

        if (empty($lastCommentId))
        {
            return false;
        }

        return ['comment_id' => $lastCommentId];
    }
}
<commit_msg>Skip already processed comments<commit_after><?php

class SV_ReportImprovements_Deferred_Upgrade_1090200 extends XenForo_Deferred_Abstract
{
    public function execute(array $deferred, array $data, $targetRunTime, &$status)
    {
        $increment = 250;
        $minCommentId = isset($data['comment_id']) ? $data['comment_id'] : -1;

        $db = XenForo_Application::getDb();

        $commentQuery = $db->query(
            "
            SELECT MAX(report_comment_id) AS max_report_comment_id
            FROM xf_report_comment 
            WHERE message LIKE '%http%' and message NOT LIKE '%[URL=%http%'
            AND report_comment_id > ?
        ", [$minCommentId]
        );
        $commentRows = $commentQuery->fetchAll();

        if (empty($commentRows) || empty($commentRows[0]) || empty($commentRows[0]['max_report_comment_id']))
        {
            return false;
        }

        $commentQuery = $db->query(
            "
            SELECT report_comment_id, message
            FROM xf_report_comment 
            WHERE message LIKE '%http%' and message NOT LIKE '%[URL=%http%'
            AND report_comment_id > ?
            ORDER BY report_comment_id
            LIMIT ?
        ", [$minCommentId, $increment]
        );

        $lastCommentId = false;
        $comments = $commentQuery->fetchAll();
        $s = microtime(true);

        if (!empty($comments))
        {
            foreach ($comments AS $comment)
            {
                $output = XenForo_Helper_String::autoLinkBbCode($comment['message']);
                if ($output !== null && $output != $comment['message'])
                {
                    $db->query(
                        '
                        UPDATE xf_report_comment
                        SET message = ?
                        WHERE report_comment_id = ?
                    ', [$output, $comment['report_comment_id']]
                    );
                }
                $lastCommentId = $comment['report_comment_id'];

                if ($targetRunTime && microtime(true) - $s > $targetRunTime)
                {
                    break;
                }
            }
        }

        if (empty($lastCommentId))
        {
            return false;
        }

        return ['comment_id' => $lastCommentId];
    }
}

{'fraction_non_alphanumeric': 0.11219081272084806, 'fraction_numerical': 0.005742049469964664, 'mean_word_length': 1.538677130044843, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 21, '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': '3834960', 'n_tokens_mistral': 1268, 'n_tokens_neox': 1173, 'n_words': 225}