Skip to content

Commit

Permalink
feat(influxdb): add setting for skipping unchanged values on database…
Browse files Browse the repository at this point in the history
… save
  • Loading branch information
Trickfilm400 committed Oct 9, 2024
1 parent 4537fb2 commit c61f11c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
6 changes: 6 additions & 0 deletions src/config/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,12 @@ const config = convict({
default: false,
env: 'INFLUXDB_ENABLED',
},
skip_same_values: {
doc: 'if the value has not changed since the last value, dont write it into the db',
format: Boolean,
default: true,
env: 'INFLUXDB_SKIP_SAME_VALUES',
},
url: {
doc: 'The URL Endpoint for InfluxDB',
format: String,
Expand Down
7 changes: 6 additions & 1 deletion src/dataHandler/influxdb.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,12 @@ export class Influxdb extends DataReceiver<DataPackage> {
const points: Point[] = [];
for (key in data) {
//skip if value has not changed since the last package to reduce load on the database saving part
if (data[key] === this.lastValues[key]) continue;
// AND setting is true to skip values
if (
config.get('influxdb.skip_same_values') &&
data[key] === this.lastValues[key]
)
continue;
const point = new Point(key);
point.floatField('value', data[key]);
points.push(point);
Expand Down

0 comments on commit c61f11c

Please sign in to comment.