From 0d57f1ec31482a412fb7a8f285a69577449e1eb3 Mon Sep 17 00:00:00 2001 From: "mergify[bot]" <37929162+mergify[bot]@users.noreply.github.com> Date: Sat, 6 Apr 2024 12:26:55 +0000 Subject: [PATCH] fix: auto add modified index when sort_field is set to it (backport #25686) (#25785) * 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* (cherry picked from commit 67bcda333ee525c9bb64ddbe7ea10f11e9fbc58c) # Conflicts: # frappe/database/mariadb/schema.py # frappe/email/smtp.py * fix: v15 compat modified is default, creation is optional on v15 * chore: conflicts --------- Co-authored-by: Ankush Menat --- frappe/database/mariadb/schema.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/frappe/database/mariadb/schema.py b/frappe/database/mariadb/schema.py index 2831e51c5d5..28c54e5b8a3 100644 --- a/frappe/database/mariadb/schema.py +++ b/frappe/database/mariadb/schema.py @@ -90,6 +90,11 @@ def alter(self): if not frappe.db.get_column_index(self.table_name, col.fieldname, unique=False): add_index_query.append(f"ADD INDEX `{col.fieldname}_index`(`{col.fieldname}`)") + if self.meta.sort_field == "creation" and frappe.db.get_column_index( + self.table_name, "creation", unique=False + ): + add_index_query.append("ADD INDEX `creation`(`creation`)") + for col in {*self.drop_index, *self.drop_unique}: if col.fieldname == "name": continue