From 51fe5d442823e25237935cdc084213f447117bea Mon Sep 17 00:00:00 2001 From: "M. Wacker" Date: Tue, 31 Mar 2020 11:05:34 +0200 Subject: [PATCH 1/3] add keys to enhance query performance --- plugins/inlineImagePlugin.php | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/plugins/inlineImagePlugin.php b/plugins/inlineImagePlugin.php index db4011a..90f2beb 100644 --- a/plugins/inlineImagePlugin.php +++ b/plugins/inlineImagePlugin.php @@ -47,15 +47,17 @@ class inlineImagePlugin extends phplistPlugin "imgid" => array("integer not null primary key auto_increment","Image numerical ID"), "file_name" => array("varchar(255) not null","File name including extension"), "cksum" => array ("varchar(45) not null", "sha1 checksum for the file contents"), - 'local_name' => array("varchar(255) not null","A unique local file name including extension"), - "type" => array("char(50)", "MIME type of the image"), - "cid" => array("char(32) not null","MIME content ID") + 'local_name' => array("varchar(255) not null","A unique local file name including extension"), + "type" => array("char(50)", "MIME type of the image"), + "cid" => array("char(32) not null","MIME content ID") ), 'msg' => array( - "id" => array("integer not null", "Message ID"), - "imgid" => array("integer not null","Image numerical ID"), + "id" => array("integer unsigned not null default 0", "Message ID"), + "imgid" => array("integer unsigned not null default 0","Image numerical ID"), "original" => array ("Text", "Original HTML image tag"), - "imagetag" => array("Text", "HTML image tag with attributes and cid") + "imagetag" => array("Text", "HTML image tag with attributes and cid"), + 'primary key' => array('(id,imgid)', ''), + 'index_1' => array('imgid(imgid)',''), ) ); // Structure of database tables for this plugin public $settings = array( @@ -579,4 +581,4 @@ function messageHeaders($mail) { } return ''; } -} \ No newline at end of file +} From 225e815cc7bb96a61c0ad5a8aa39a906d258fa29 Mon Sep 17 00:00:00 2001 From: "M. Wacker" Date: Tue, 31 Mar 2020 11:07:05 +0200 Subject: [PATCH 2/3] remov unused query --- plugins/inlineImagePlugin.php | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/plugins/inlineImagePlugin.php b/plugins/inlineImagePlugin.php index 90f2beb..8dee15e 100644 --- a/plugins/inlineImagePlugin.php +++ b/plugins/inlineImagePlugin.php @@ -232,11 +232,7 @@ function allowMessageToBeQueued($messagedata = array()) $msgtbl = $GLOBALS['tables']['inlineImagePlugin_msg']; $msg = $messagedata['message']; - $id = $messagedata['id']; - - // We could get here if a message has been queued and then suspended for - // re-editing. So make sure that we have not stored any data for this message - $query = sprintf ("select * from %s where id=%d", $msgtbl, $id); + $id = $messagedata['id']; $tempfile = $this->coderoot . 'images/tempimg.tmp'; $limit = getConfig("ImageAttachLimit"); From 1fb1fa83269f232fe74743c6c35162ee06c4c4db Mon Sep 17 00:00:00 2001 From: "M. Wacker" Date: Tue, 31 Mar 2020 11:11:13 +0200 Subject: [PATCH 3/3] prevent select * for performance reason is the select query to get number counts really necessary? the delete query might be enought, since it won't delete non-existant rows anyway. but since the select query makes use of the index, it is very quick and might not have a huge impact. --- plugins/inlineImagePlugin.php | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/plugins/inlineImagePlugin.php b/plugins/inlineImagePlugin.php index 8dee15e..3b1f660 100644 --- a/plugins/inlineImagePlugin.php +++ b/plugins/inlineImagePlugin.php @@ -297,7 +297,16 @@ private function saveImageData ($msgdata = array()) { $id = $msgdata ['id']; $msg = $msgdata['message']; - $query = sprintf ("select * from %s where id=%d", $msgtbl, $id); + $query = sprintf ("select imgid from %s where id=%d", $msgtbl, $id); + + // Remove old data connecting this message with its images.We save the new data + // below. We don't bother clearing old images from the + // directory here, because they will eventually be deleted anyway, as we clean + // older files from the database + if (Sql_Num_Rows(Sql_Query($query)) > 0) { + $query = sprintf("delete from %s where id=%d", $msgtbl, $id); + Sql_Query($query); + } // Merge the message and template to check the images // Make sure that we have all parts of the message that may contain images @@ -310,16 +319,7 @@ private function saveImageData ($msgdata = array()) { if (strpos($msg, "[FOOTER]") !== false) $msg = str_ireplace("[FOOTER]", $msgdata["footer"],$msg); else // Phplist always adds a footer. - $msg .= $msgdata["footer"]; // We're not constructing the message, just collecting inline image files - - // Remove old data connecting this message with its images.We save the new data - // below. We don't bother clearing old images from the - // directory here, because they will eventually be deleted anyway, as we clean - // older files from the database - if (Sql_Num_Rows(Sql_Query($query)) > 0) { - $query = sprintf("delete from %s where id=%d", $msgtbl, $id); - Sql_Query($query); - } + $msg .= $msgdata["footer"]; // We're not constructing the message, just collecting inline image files // Collect the inline image tags preg_match_all('#]+\Winline(?:\W.*(?:/)?)?>#Ui', $msg, $match);