Announcement

Collapse
No announcement yet.

Unnecessary code causes slow queries up to 1 minute

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Unnecessary code causes slow queries up to 1 minute

    admin/functions.php

    Function: deletepost()

    PHP Code:
    [color=black]// ###################### Start delete post #######################
    function deletepost($postid,$countposts=1,$threadid=0) {
    global 
    $DB_site;[/color]
     
    [
    color=black]// decrement user post count
    if ($postinfo=getpostinfo($postid)) {
        if (
    $countposts) {
         
    $DB_site->query("UPDATE user SET posts=posts-1 WHERE userid='$postinfo[userid]'");
        }
        if (
    $postinfo['attachmentid']) {
    // make sure you don't remove attachments still in use
    $otherattachs=$DB_site->query("SELECT attachmentid FROM post WHERE attachmentid=$postinfo[attachmentid] AND threadid<>'$postinfo[threadid]'");
    if (
    $DB_site->num_rows($otherattachs)==0) {
        
    $DB_site->query("DELETE FROM attachment WHERE attachmentid=$postinfo[attachmentid]");
            
    $DB_site->query("UPDATE thread SET attach = attach - 1 WHERE threadid = '$threadid'");
    }
        }[/
    color]
     
    [
    color=black]    $DB_site->query("DELETE FROM post WHERE postid='$postid'");
    }
    }[/
    color]
    [
    color=black][/color


    Please notice this code snippet from the above function:

    PHP Code:
    [color=black]    if ($postinfo['attachmentid']) {
    // make sure you don't remove attachments still in use
    $otherattachs=$DB_site->query("SELECT attachmentid FROM post WHERE attachmentid=$postinfo[attachmentid] AND threadid<>'$postinfo[threadid]'");
    [/
    color


    This query seems completely unnecessary and with a large vB, over 1 million posts, this query can take up to a minute with no key on post.attachmentid. All rows will have to be examined in this case.

    My question is, when could this error checking ever be necessary? The only thing I can think is if someone manually changed an attachmentid in the post table, which would cause other problems anyway.

    vB Devs, do you think this slow error checking is necessary?

    Thanks
    http://www.teamxbox.com

  • #2
    bump
    http://www.teamxbox.com

    Comment

    Loading...
    Working...
    X