From 85cef317f2bea7ecf81805309d6d0399cdd357bd Mon Sep 17 00:00:00 2001 From: Ankush Menat Date: Thu, 15 Jun 2023 18:03:09 +0530 Subject: [PATCH 1/2] perf: Index `everyone` in DocShare A typical share query looks like this. select `share_name` from `tabDocShare` where `tabDocShare`.`read` = 1.0 and `tabDocShare`.`share_doctype` = 'Pick List' and (`tabDocShare`.`user` = 'username' or `tabDocShare`.`everyone` = 1.0) order by `tabDocShare`.`modified` DESC; None of existing indexes provide `everyone` values quickly, so `OR` clause effectively clauses full table scan ALL THE TIME. --- frappe/core/doctype/docshare/docshare.json | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/frappe/core/doctype/docshare/docshare.json b/frappe/core/doctype/docshare/docshare.json index ca10b05dac..e3581f516e 100644 --- a/frappe/core/doctype/docshare/docshare.json +++ b/frappe/core/doctype/docshare/docshare.json @@ -67,7 +67,8 @@ "default": "0", "fieldname": "everyone", "fieldtype": "Check", - "label": "Everyone" + "label": "Everyone", + "search_index": 1 }, { "default": "1", @@ -85,10 +86,11 @@ ], "in_create": 1, "links": [], - "modified": "2021-04-04 11:38:50.813312", + "modified": "2023-06-15 18:02:51.877533", "modified_by": "Administrator", "module": "Core", "name": "DocShare", + "naming_rule": "Random", "owner": "Administrator", "permissions": [ { @@ -106,5 +108,6 @@ "read_only": 1, "sort_field": "modified", "sort_order": "DESC", + "states": [], "track_changes": 1 } \ No newline at end of file From e9645b759fe32a6aee732b1eb9c7569fefe22422 Mon Sep 17 00:00:00 2001 From: Ankush Menat Date: Thu, 15 Jun 2023 18:07:06 +0530 Subject: [PATCH 2/2] perf: Dont order_by while fetching shares Unnecessary confusion to query planner --- frappe/share.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frappe/share.py b/frappe/share.py index adae95ea23..6c2fb356a6 100644 --- a/frappe/share.py +++ b/frappe/share.py @@ -161,7 +161,7 @@ def get_shared(doctype, user=None, rights=None): or_filters += [["everyone", "=", 1]] shared_docs = frappe.get_all( - "DocShare", fields=["share_name"], filters=filters, or_filters=or_filters + "DocShare", fields=["share_name"], filters=filters, or_filters=or_filters, order_by=None ) return [doc.share_name for doc in shared_docs]