Skip to content
Permalink
Browse files

Merge pull request #264 from Anisan/alpha

optimize cycle phistory
  • Loading branch information
sergejey committed Aug 9, 2018
2 parents 6533ebc + 9eb19fb commit 54983893eb8486b8d2e1de48e0f2d3f1eacc2cc7
Showing with 35 additions and 12 deletions.
  1. +12 −0 modules/xray/xray.class.php
  2. +23 −12 scripts/cycle_phistory.php
@@ -382,6 +382,13 @@ function admin(&$out) {
}
}
}
if ($this->view_mode=='timers') {
global $cmd;
global $timer;
if ($cmd=='stop' && $timer!='') {
clearScheduledJob($timer);
}
}
if ($ajax) {
global $op;
@@ -690,6 +697,7 @@ function admin(&$out) {
echo '<td><b>TIMER</b></td>';
echo '<td><b>COMMAND</b></td>';
echo '<td><b>SCHEDULED</b></td>';
echo '<td></td>';
echo '</tr>';
for($i=0;$i<$total;$i++) {
echo '<tr>';
@@ -702,6 +710,10 @@ function admin(&$out) {
echo '<td>';
echo $res[$i]['RUNTIME'].'&nbsp;';
echo '</td>';
echo '<td>';
$url=ROOTHTML.'panel/xray.html?view_mode=timers&timer='.urlencode($res[$i]['TITLE']);
echo '<a href="'.$url.'&cmd=stop" class="btn btn-default">Stop</a>';
echo '</td>';
echo '</tr>';
}
echo '</table>';
@@ -21,6 +21,11 @@
SQLExec("OPTIMIZE TABLE phistory;");
debug_echo("Done");
$limit=(int)gg('phistory_queue_limit');
if (!$limit) {
$limit=200;
}
$checked_time = 0;
echo date("H:i:s") . " running " . basename(__FILE__) . "\n";
@@ -51,9 +56,22 @@
}
}
*/
$queue_error_status=gg('phistory_queue_problem');
$queue = SQLSelect("SELECT * FROM phistory_queue ORDER BY ID LIMIT 500");
$tmp=SQLSelectOne("SELECT COUNT(*) as TOTAL FROM phistory_queue;");
$count_queue = (int)$tmp['TOTAL'];
$queue = SQLSelect("SELECT * FROM phistory_queue ORDER BY ID LIMIT ". $limit);
if ($queue[0]['ID']) {
if ($count_queue>$limit && !$queue_error_status) {
sg('phistory_queue_problem',1);
$txt = 'Properties history queue is too long ('.$count_queue.')';
echo date("H:i:s") . " " . $txt . "\n";
registerError('phistory_queue',$txt);
} elseif ($count_queue<=$limit && $queue_error_status) {
sg('phistory_queue_problem',0);
}
$total = count($queue);
$processed = array();
for ($i = 0; $i < $total; $i++) {
@@ -62,15 +80,7 @@
$old_value = $q_rec['OLD_VALUE'];
debug_echo("Queue $i / $total");
$queue_error_status=gg('phistory_queue_problem');
if ($total>200 && !$queue_error_status) {
sg('phistory_queue_problem',1);
registerError('phistory_queue','Properties history queue is too long ('.$total.')');
} elseif ($total<=200 && $queue_error_status) {
sg('phistory_queue_problem',0);
}
SQLExec("DELETE FROM phistory_queue WHERE ID='" . $q_rec['ID'] . "'");
if (defined('SEPARATE_HISTORY_STORAGE') && SEPARATE_HISTORY_STORAGE == 1) {
@@ -107,7 +117,7 @@
$h['VALUE_ID'] = $q_rec['VALUE_ID'];
$h['ADDED'] = $q_rec['ADDED'];
$h['VALUE'] = $value;
debug_echo(" Insert new value ".$h['VALUE_ID']);
debug_echo(" Insert new value ".$h['VALUE_ID']." ".$h['ADDED']." ".$value);
$h['ID'] = SQLInsert($table_name, $h);
debug_echo(" Done ");
} elseif ($value == $old_value) {
@@ -143,12 +153,13 @@
}
}
else
sleep(1);
if (file_exists('./reboot') || IsSet($_GET['onetime'])) {
$db->Disconnect();
exit;
}
sleep(1);
}
function debug_echo($line) {

0 comments on commit 5498389

Please sign in to comment.
You can’t perform that action at this time.