patch: optimisations

This commit is contained in:
Himanshu Warekar 2019-05-18 18:54:47 +05:30
parent defe1b2eef
commit 6403cf45ae

View file

@ -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 = []