fix(communication): Make optimizations to the patch
* use batches to move Timeline and Links to Timeline Links doctype
This commit is contained in:
parent
b8508de933
commit
59c945bb84
1 changed files with 29 additions and 31 deletions
|
|
@ -6,41 +6,39 @@ def execute():
|
|||
frappe.reload_doc('core', 'doctype', 'communication')
|
||||
|
||||
communications = frappe.db.sql("""
|
||||
SELECT
|
||||
`tabCommunication`.name, `tabCommunication`.creation, `tabCommunication`.modified,
|
||||
`tabCommunication`.modified_by,`tabCommunication`.timeline_doctype, `tabCommunication`.timeline_name,
|
||||
`tabCommunication`.link_doctype, `tabCommunication`.link_name
|
||||
FROM `tabCommunication`
|
||||
WHERE `tabCommunication`.communication_medium='Email'
|
||||
""", as_dict=True)
|
||||
SELECT
|
||||
`tabCommunication`.name, `tabCommunication`.creation, `tabCommunication`.modified,
|
||||
`tabCommunication`.modified_by,`tabCommunication`.timeline_doctype, `tabCommunication`.timeline_name,
|
||||
`tabCommunication`.link_doctype, `tabCommunication`.link_name
|
||||
FROM `tabCommunication`
|
||||
WHERE `tabCommunication`.communication_medium='Email'
|
||||
""", as_dict=True)
|
||||
|
||||
name = 10000000000001234567
|
||||
values = []
|
||||
|
||||
for count, communication in enumerate(communications):
|
||||
counter = 1
|
||||
if communication.timeline_doctype and communication.timeline_name:
|
||||
values = [
|
||||
counter, frappe.generate_hash(length=10), 'timeline_links', 'Communication', communication.name,
|
||||
communication.timeline_doctype, communication.timeline_name, communication.creation, communication.modified,
|
||||
communication.modified_by
|
||||
]
|
||||
execute_query(values)
|
||||
name += 1
|
||||
values.append("""({0}, "{1}", "timeline_links", "Communication", "{2}", "{3}", "{4}", "{5}", "{6}", "{7}")""".format(
|
||||
counter, str(name), 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:
|
||||
values = [
|
||||
counter, frappe.generate_hash(length=10), 'timeline_links', 'Communication', communication.name,
|
||||
communication.link_doctype, communication.link_name, communication.creation, communication.modified,
|
||||
communication.modified_by
|
||||
]
|
||||
execute_query(values)
|
||||
name += 1
|
||||
values.append("""({0}, "{1}", "timeline_links", "Communication", "{2}", "{3}", "{4}", "{5}", "{6}", "{7}")""".format(
|
||||
counter, str(name), communication.name, communication.link_doctype,
|
||||
communication.link_name, communication.creation, communication.modified, communication.modified_by
|
||||
))
|
||||
|
||||
def execute_query(values):
|
||||
try:
|
||||
frappe.db.sql("""
|
||||
INSERT INTO `tabDynamic Link`
|
||||
(`idx`, `name`, `parentfield`, `parenttype`, `parent`, `link_doctype`, `link_name`, `creation`,
|
||||
`modified`, `modified_by`)
|
||||
VALUES ({0}, {1}, {2}, {3}, {4}, {5}, {6}, {7}, {8}, {9})
|
||||
""".format(values[0], values[1], values[2], values[3], values[4], values[5], values[6], values[7], values[8], values[9]))
|
||||
except Exception as e:
|
||||
values[1] = frappe.generate_hash(length=10)
|
||||
execute_query(values)
|
||||
if count % 10000 == 0 or count == len(communications) - 1:
|
||||
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])))
|
||||
|
||||
values = []
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue