From 67bcda333ee525c9bb64ddbe7ea10f11e9fbc58c Mon Sep 17 00:00:00 2001 From: Ankush Menat Date: Wed, 27 Mar 2024 20:10:26 +0530 Subject: [PATCH] fix: auto add modified index when sort_field is set to it (#25686) This is 2nd most common sort order, so we should support adding index for it automatically. Not quite sure on generalizing this behaviour *YET* --- frappe/database/mariadb/schema.py | 6 ++++++ frappe/email/smtp.py | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/frappe/database/mariadb/schema.py b/frappe/database/mariadb/schema.py index 34864f2d5f..3465058631 100644 --- a/frappe/database/mariadb/schema.py +++ b/frappe/database/mariadb/schema.py @@ -84,6 +84,12 @@ class MariaDBTable(DBTable): for col in self.add_index if not frappe.db.get_column_index(self.table_name, col.fieldname, unique=False) ] + + if self.meta.sort_field == "modified" and frappe.db.get_column_index( + self.table_name, "modified", unique=False + ): + add_index_query.append("ADD INDEX `modified`(`modified`)") + drop_index_query = [] for col in {*self.drop_index, *self.drop_unique}: diff --git a/frappe/email/smtp.py b/frappe/email/smtp.py index 12d8af38f3..2b64c8e528 100644 --- a/frappe/email/smtp.py +++ b/frappe/email/smtp.py @@ -109,7 +109,7 @@ class SMTPServer: frappe.request.after_response.add(self.quit) elif frappe.job: frappe.job.after_job.add(self.quit) - else: + elif not frappe.flags.in_test: # Console? import atexit