]> git.ipfire.org Git - thirdparty/patchwork.git/commitdiff
parser: avoid an unnecessary UPDATE of Person
authorDaniel Axtens <dja@axtens.net>
Sun, 18 Feb 2018 08:06:23 +0000 (19:06 +1100)
committerDaniel Axtens <daniel.axtens@canonical.com>
Tue, 6 Mar 2018 14:32:42 +0000 (01:32 +1100)
Analysis of SQL statements showed that when parsing an email, the row
for the Person who sent the email was always getting updated. This is
because the test for updating it only checks if the incoming mail has
*a* name attached to the email address, and not if it has a new name.
Django is not smart enough to figure that out, and so unconditionally
UPDATEs the model when asked to save.

Give it a hand - only update the model and save it if the new name is
in fact different.

Reviewed-by: Andrew Donnellan <andrew.donnellan@au1.ibm.com>
Reviewed-by: Stephen Finucane <stephen@that.guru>
Signed-off-by: Daniel Axtens <dja@axtens.net>
patchwork/parser.py

index 6be37ec65fd851d875fbe06294fa17244f778fb5..f84f905d213cfc3e9e38c0f15a14a202088c1aba 100644 (file)
@@ -345,7 +345,7 @@ def get_or_create_author(mail):
                                           defaults={'name': name,
                                                     'email': email})[0]
 
-    if name:  # use the latest provided name
+    if name and name != person.name:  # use the latest provided name
         person.name = name
         person.save()