buildlogs: index.php Limit array_splice calls to lower value.
arekm
arekm at pld-linux.org
Mon Oct 13 00:38:57 CEST 2014
Author: arekm Date: Sun Oct 12 22:38:57 2014 GMT
Module: buildlogs Tag: HEAD
---- Log message:
Limit array_splice calls to lower value.
---- Files affected:
buildlogs:
index.php (1.27 -> 1.28)
---- Diffs:
================================================================
Index: buildlogs/index.php
diff -u buildlogs/index.php:1.27 buildlogs/index.php:1.28
--- buildlogs/index.php:1.27 Mon Oct 13 00:07:53 2014
+++ buildlogs/index.php Mon Oct 13 00:38:52 2014
@@ -351,14 +351,16 @@
$cmd = "$filter '$root_directory/$f'";
$fd = popen($cmd, "r");
+ $line_idx = 0;
+ $processing_idx = 0;
$toc = array();
$err = array();
$err_count = 0;
- $tail_end = 0;
$time = "";
$out_buf = array();
$out_buf_size = 0;
while (($s = fgets($fd, 102400)) != false) {
+
if (strlen($s) > 800) {
$s = chunk_split($s, 800, "\n ");
$s = trim($s);
@@ -393,8 +395,8 @@
$err_elem = $s;
$s = "<span class=section id={$m['section']}>$s</span>";
} elseif (preg_match("/^Processing files: (?P<pkg>(?P<name>.+)-[^-]+-[^-]+)/", $s, $m)) {
+ $processing_idx = $line_idx;
// processing files
- $tail_end++;
$toc_elem = "files ".$m['name'];
$err_elem = $s;
$s = "<span class=section id=files-{$m['name']}>$s</span>";
@@ -402,21 +404,32 @@
$time = $m['time'];
}
- $out_buf[] = $s;
+ $out_buf[$line_idx] = $s;
$out_buf_size++;
+
+ // if error/processing found truncate early but keep last 100 lines before error
+ if ($tail && ($err_count == 1 || ($err_count == 0 && $processing_idx == $line_idx)) && $out_buf_size > 100) {
+ array_splice($out_buf, 0, $out_buf_size - 100);
+ $out_buf_size = 100;
+ }
+
// if (not in tail mode) or (in tail mode but we have an error)
- if (!$tail || $err_count || $tail_end) {
+ if (!$tail || $err_count || $processing_idx) {
if ($toc_elem)
$toc[] = $toc_elem;
if ($err_elem)
$err[] = $err_elem;
- } else if ($out_buf_size > 100) {
- // truncate to last 100 elements
- $out_buf_size -= 100;
- $out_buf = array_splice($out_buf, 0, $out_buf_size);
}
+
+ $line_idx++;
}
pclose($fd);
+
+ // no errors found, no processing found but we are in tail mode
+ if ($tail && $err_count == 0 && $processing_idx == 0 && $out_buf_size > 100) {
+ array_splice($out_buf, 0, $out_buf_size - 100);
+ $out_buf_size = 100;
+ }
$code = join('', $out_buf);
================================================================
---- CVS-web:
http://cvs.pld-linux.org/buildlogs/index.php?r1=1.27&r2=1.28
More information about the pld-cvs-commit
mailing list