Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

SQL optimization in action_tag()

  • Loading branch information...
commit 4b61bbebe551349ee021bb9d9d5430f2e2d522f8 1 parent c467fef
@manitou-mail authored
Showing with 2 additions and 9 deletions.
  1. +2 −9 lib/Manitou/Tags.pm
View
11 lib/Manitou/Tags.pm
@@ -45,15 +45,8 @@ sub get_sequence_nextval {
sub action_tag {
my ($dbh, $mail_id, $tag_id) = @_;
- # See if the tag isn't already set
- my $sth1=$dbh->prepare("SELECT 1 FROM mail_tags WHERE mail_id=? AND tag=?");
- $sth1->execute($mail_id, $tag_id);
- my @r=$sth1->fetchrow_array;
- if (!@r) {
- # If not, then set it
- my $sth=$dbh->prepare("INSERT INTO mail_tags(mail_id,tag) VALUES (?,?)");
- $sth->execute ($mail_id, $tag_id);
- }
+ my $sth=$dbh->prepare("INSERT INTO mail_tags(mail_id,tag) SELECT ?,? WHERE NOT EXISTS (SELECT 1 FROM mail_tags WHERE mail_id=? AND tag=?)");
+ $sth->execute($mail_id, $tag_id, $mail_id, $tag_id);
}
Please sign in to comment.
Something went wrong with that request. Please try again.