Skip to content

Commit

Permalink
fix: auto add modified index when sort_field is set to it (backport #…
Browse files Browse the repository at this point in the history
…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 67bcda3)

# 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 <ankush@frappe.io>
  • Loading branch information
mergify[bot] and ankush committed Apr 6, 2024
1 parent 176cbd3 commit 0d57f1e
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions frappe/database/mariadb/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 0d57f1e

Please sign in to comment.