diff --git a/frappe/patches/v12_0/move_timeline_links_to_dynamic_links.py b/frappe/patches/v12_0/move_timeline_links_to_dynamic_links.py index 9d6cfffb84..507ed05e18 100644 --- a/frappe/patches/v12_0/move_timeline_links_to_dynamic_links.py +++ b/frappe/patches/v12_0/move_timeline_links_to_dynamic_links.py @@ -5,11 +5,6 @@ import frappe def execute(): frappe.reload_doc('core', 'doctype', 'communication') - sql_query = """INSERT INTO `tabDynamic Link` - (`idx`, `name`, `parentfield`, `parenttype`, `parent`, `link_doctype`, `link_name`, `creation`, - `modified`, `modified_by`) - VALUES """ - communications = frappe.db.sql(""" Select `tabCommunication`.name, `tabCommunication`.creation, `tabCommunication`.modified, @@ -19,21 +14,32 @@ def execute(): where `tabCommunication`.communication_medium='Email' """, as_dict=True) - for communication in communications: + values = [] + for count, communication in enumerate(communications): counter = 1 if communication.timeline_doctype and communication.timeline_name: - sql_query += str(( - counter, frappe.generate_hash(length=10), "timeline_links", "Communication", communication.name, - communication.timeline_doctype, communication.timeline_name, communication.creation, - communication.modified, communication.modified_by - )) + """, """ + values.append("""({0}, '{1}', 'timeline_links', 'Communication', '{2}', '{3}', '{4}', '{5}', '{6}', '{7}')""".format( + counter, frappe.generate_hash(length=10), communication.name, communication.timeline_doctype, + communication.timeline_name, communication.creation, communication.modified, communication.modified_by + )) counter += 1 - if communication.link_doctype and communication.link_name: - sql_query += str(( - counter, frappe.generate_hash(length=10), "timeline_links", "Communication", communication.name, - communication.link_doctype, communication.link_name, communication.creation, - communication.modified, communication.modified_by - )) + """, """ - - frappe.db.sql(sql_query) + values.append("""({0}, '{1}', 'timeline_links', 'Communication', '{2}', '{3}', '{4}', '{5}', '{6}', '{7}')""".format( + counter, frappe.generate_hash(length=10), communication.name, communication.link_doctype, + communication.link_name, communication.creation, communication.modified, communication.modified_by + )) + if count % 200 == 0 or count == len(communications) - 1: + print(""" + INSERT INTO `tabDynamic Link` + (`idx`, `name`, `parentfield`, `parenttype`, `parent`, `link_doctype`, `link_name`, `creation`, + `modified`, `modified_by`) + VALUES {0} + """.format(", ".join([d for d in values]))) + frappe.db.sql(""" + INSERT INTO `tabDynamic Link` + (`idx`, `name`, `parentfield`, `parenttype`, `parent`, `link_doctype`, `link_name`, `creation`, + `modified`, `modified_by`) + VALUES {0} + """.format(", ".join([d for d in values]))) + # frappe.throw("YA") + values = [] \ No newline at end of file