所以我有一个“注释”字段,它正在将一行(assigned_user_id)更新为新的 id。笔记是大约。长度为 160k。users 表大约有 300 个。
对于每个注释行,我将assigned_user_id 与 users 表进行比较,如果找到匹配项,则获取新的用户 ID 并更新 notes 表。冲洗重复:
//dis-allow timeout. Was timing out consistently under 100 rows changes.
set_time_limit(0);
ignore_user_abort(1);
//foreach note
$counter = 0;
foreach ( $msCRMAnnotations as $key=>$value)
{
//foreach user, check for match between assigned_user_id and id_mscrm
foreach( $sugarCRMUsers as $key2=>$value2 )
{
if($value['assigned_user_id'] == $value2['id_mscrm'] )
{
//give some output as to what is changing...
echo("Note #" . $counter++ . " - Note id " . $value['id'] . " is assigned to user " . $value2['user_name'] . ".<br />" );
$query = "
UPDATE `notes`
SET `assigned_user_id` = '" . $value2['id'] . "'
WHERE `id` = '" . $value['id'] . "' AND
`assigned_user_id` = '" . $value['assigned_user_id'] . "'
";
$DB->query($query);
//unset($query);
}
}
}
具体来说,我们正在将选定数据从 MsCRM 迁移到 SugarCRM。这是项目的帐户/注释/用户阶段。
所以现在的问题....我怎样才能最好地重构上面的代码以提高性能?非常感谢任何和所有帮助。