Reply to thread

[php]

\XF::db()->query("

    UPDATE (

        SELECT content_id FROM xf_reaction_content

        WHERE content_type = ?

        AND reaction_user_id = ?

    ) AS temp

    INNER JOIN {$table} AS reaction_table ON (reaction_table.`$primaryKey` = temp.content_id)

    SET reaction_table.`{$recentField}` = REPLACE(reaction_table.`{$recentField}`, ?, ?)

", [$this->contentType, $newUserId, $oldFind, $newReplace]);

[/php]


This query tries to update all records for $newUserId, even those whre nothing needs to be changed.


In case $newUserId is 0 this could hit a lot of unaffected records (if there are already many reactions by deleted users).

See related issue https://xenforo.com/community/threads/service-xf-user-changecontent-runs-twice-when-renaming-a-user-upon-deletion.217244/


Changing this to smth. like

[php]

\XF::db()->query("

    UPDATE (

        SELECT content_id FROM xf_reaction_content

        WHERE content_type = ?

        AND reaction_user_id = ?

    ) AS temp

    INNER JOIN {$table} AS reaction_table ON (reaction_table.`$primaryKey` = temp.content_id)

    SET reaction_table.`{$recentField}` = REPLACE(reaction_table.`{$recentField}`, ?, ?)

    WHERE reaction_table.`{$recentField}` LIKE ?

", [$this->contentType, $newUserId, $oldFind, $newReplace, '%' . \XF::db()->escapeLike($oldFind) . '%']);

[/php]


seems to significantly speed up the query in those cases.


Back
Top Bottom