Skip to content

Commit

Permalink
skipbuffer option on feed insert
Browse files Browse the repository at this point in the history
  • Loading branch information
TrystanLea committed Feb 3, 2021
1 parent 58ab20f commit 48d4063
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 7 deletions.
4 changes: 2 additions & 2 deletions Modules/feed/Views/feedapi_view.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,10 +90,10 @@
</td></tr>
<tr><td><?php echo _("Insert multiple data points");?></td><td>
<?php $data = array(); for($i=0; $i<4; $i++) { $data[] = array(floor((time()+($i*10))*0.1)*10,100+50*$i); } ?>
<a href="<?php echo $path; ?>feed/insert.json?id=0&data=<?php echo json_encode($data); ?>"><?php echo $path; ?>feed/insert.json?id=0&data=<?php echo json_encode($data); ?></a>
<a href="<?php echo $path; ?>feed/insert.json?id=0&data=<?php echo json_encode($data); ?>"><?php echo $path; ?>feed/insert.json?id=0&data=<?php echo json_encode($data); ?></a> (add &skipbuffer=1 to update existing or missing data)
</td></tr>
<tr><td><?php echo _("Update data point");?></td><td>
<a href="<?php echo $path; ?>feed/update.json?id=0&time=UNIXTIME&value=100.0"><?php echo $path; ?>feed/update.json?id=0&time=UNIXTIME&value=100.0</a>
<a href="<?php echo $path; ?>feed/update.json?id=0&time=UNIXTIME&value=100.0&skipbuffer=1"><?php echo $path; ?>feed/update.json?id=0&time=UNIXTIME&value=100.0&skipbuffer=1</a>
</td></tr>
<tr><td><?php echo _("Delete data point");?></td><td>
<a href="<?php echo $path; ?>feed/deletedatapoint.json?id=0&feedtime=UNIXTIME"><?php echo $path; ?>feed/deletedatapoint.json?id=0&feedtime=UNIXTIME</a>
Expand Down
6 changes: 4 additions & 2 deletions Modules/feed/feed_controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -227,9 +227,11 @@ function feed_controller()
// Insert datapoint
} else if ($route->action == "insert") {

$skipbuffer = false; if (isset($_GET['skipbuffer'])) $skipbuffer = true;

// Single data point
if (isset($_GET['time']) || isset($_GET['value'])) {
return $feed->insert_data($feedid,time(),get("time"),get("value"));
return $feed->insert_data($feedid,time(),get("time"),get("value"),null,$skipbuffer);
}

// Single or multiple datapoints via json format
Expand All @@ -248,7 +250,7 @@ function feed_controller()

foreach ($data as $dp) {
if (count($dp)==2) {
$feed->insert_data($feedid,$dp[0],$dp[0],$dp[1]);
$feed->insert_data($feedid,$dp[0],$dp[0],$dp[1],null,$skipbuffer);
}
}
return array('success'=>true);
Expand Down
6 changes: 3 additions & 3 deletions Modules/feed/feed_model.php
Original file line number Diff line number Diff line change
Expand Up @@ -908,9 +908,9 @@ public function set_timevalue($id, $value, $time)
}
}

public function insert_data($feedid,$updatetime,$feedtime,$value,$arg=null)
public function insert_data($feedid,$updatetime,$feedtime,$value,$arg=null,$skipbuffer=false)
{
$this->log->info("insert_data() feedid=$feedid updatetime=$updatetime feedtime=$feedtime value=$value arg=$arg");
$this->log->info("insert_data() feedid=$feedid updatetime=$updatetime feedtime=$feedtime value=$value arg=$arg skipbuffer=$skipbuffer");
$feedid = (int) $feedid;
if (!$this->exist($feedid)) return array('success'=>false, 'message'=>'Feed does not exist');

Expand All @@ -920,7 +920,7 @@ public function insert_data($feedid,$updatetime,$feedtime,$value,$arg=null)
$value = floatval($value);

$engine = $this->get_engine($feedid);
if ($this->settings['redisbuffer']['enabled']) {
if ($this->settings['redisbuffer']['enabled'] && !$skipbuffer) {
// Call to buffer post
$args = array('engine'=>$engine,'updatetime'=>$updatetime,'arg'=>$arg);
$this->EngineClass(Engine::REDISBUFFER)->post($feedid,$feedtime,$value,$args);
Expand Down

0 comments on commit 48d4063

Please sign in to comment.