我的目标是从“p4 更改”中提取 POST 响应中给定更改编号的更改编号/日期/时间/描述。我制作了一个简单的 PHP 脚本,它解析必要的 shell 命令(虽然很麻烦,但它可以工作)并填充一个 JSON 数组。
一切正常,直到我开始查看 'p4 describe -s' 并在其中解析出一个特殊字段,我们在其中列出了与 changenum 相关的错误,如下所示:
bug2342 状态已修复;
bug2343 状态已修复;
该脚本必须对每个 changenum 执行单独的“p4 describe”,这当然需要一段时间。我看到 30+ 秒的响应时间,范围约为 1000 个更改号 :(
我能做些什么来加快速度?我什至考虑在前端做两遍:首先获取所有的changenum,显示它们(将错误ID留空)然后异步获取大约10个左右的批次的错误编号,并迭代地填充丢失的数据。
$cmd = 'p4 changes -t -s submitted -l //depot/...@' . $changenum1 . ',' . $changenum2 . ' 2>&1 |
awk \'BEGIN { RS = "^Change |\n^Change "; FS = "^Change |\n^Change " } {print $1 "::::"}\'';
$output = shell_exec($cmd);
$changes = split("::::", trim($output));
$cc = array();
$i = 0;
foreach ($changes as $change) {
if (empty($change)) {
continue;
}
//example here: '3193358 on 2012/10/08 11:05:42 by user@client\n "some lengthy multiline description"'
$change = trim($change);
$c = array();
$basics = preg_split( "/( |\n)/", $change);
$c["cnum"] = $basics[0];
$c["date"] = $basics[2];
$c["time"] = $basics[3];
$user = $basics[5];
$c["user"] = preg_replace('/@.*/', "", $user);
//echo "cnum: $c["cnum"], date: $c["date"]], time: $c["time"], user: $c["user"]";
//THIS IS VERY SLOW
$cmd2 = 'p4 describe -s ' . $c["cnum"] . ' 2>&1 | egrep "^bug[0-9]+" | sed -re "s/bug([0-9]+).*/\1/"';
$output2 = shell_exec($cmd2);
$bugs = split("\n", trim($output2));
$c["bugs"] = $bugs;
$pos = strpos($change, "\n"); //remove first line
if ($pos !== false) {
$description = substr($change, $pos +1);
} else {
$description = $change;
}
//remove multiple whitespace
$description2 = preg_replace('/\s+/', ' ', $description);
//remove blank new lines etc
$description3 = preg_replace('/^\n+|^[\t\s]*\n+/m', "", $description2);
$c["desc"] = trim($description3);
$cc[$i++] = $c;
}
$output = __json_encode($cc);