Insert records into global search table in small batches, added progress bar in patch (#3313)

This commit is contained in:
Nabin Hait 2017-05-17 19:51:44 +05:30 committed by GitHub
parent 8657751554
commit 44619bcf38
2 changed files with 15 additions and 8 deletions

View file

@ -1,7 +1,11 @@
import frappe
from frappe.utils.global_search import get_doctypes_with_global_search, rebuild_for_doctype
from frappe.utils import update_progress_bar
def execute():
frappe.cache().delete_value('doctypes_with_global_search')
for doctype in get_doctypes_with_global_search(with_child_tables=False):
doctypes_with_global_search = get_doctypes_with_global_search(with_child_tables=False)
for i, doctype in enumerate(doctypes_with_global_search):
update_progress_bar("Updating Global Search", i, len(doctypes_with_global_search))
rebuild_for_doctype(doctype)

View file

@ -182,13 +182,16 @@ def insert_values_for_multiple_docs(all_contents):
values.append("( '{doctype}', '{name}', '{content}', '{published}', '{title}', '{route}')"
.format(**content))
# ignoring duplicate keys for doctype_name
frappe.db.sql('''
insert ignore into __global_search
(doctype, name, content, published, title, route)
values
{0}
'''.format(", ".join(values)))
batch_size = 50000
for i in range(0, len(values), batch_size):
batch_values = values[i:i + batch_size]
# ignoring duplicate keys for doctype_name
frappe.db.sql('''
insert ignore into __global_search
(doctype, name, content, published, title, route)
values
{0}
'''.format(", ".join(batch_values)))
def update_global_search(doc):