Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optimize handling of ignoreTopics ending with "," #422

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 10 additions & 7 deletions lib/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,17 @@ function MQTTClient(adapter, states) {
const verifiedObjects = {};

const ignoredTopicsRegexes = [];
if(adapter.config.ignoredTopics) {
const ignoredTopics = adapter.config.ignoredTopics.split(',');
for (const ignoredTopicPattern of ignoredTopics) {
const ignoredTopicRegexWithNameSpace = pattern2RegEx(`${adapter.namespace}.${ignoredTopicPattern}`, adapter);
const ignoredTopicRegex = pattern2RegEx(ignoredTopicPattern, adapter);
adapter.log.info(`Ignoring topic with pattern: ${ignoredTopicPattern} (RegExp: ${ignoredTopicRegex} und ${ignoredTopicRegexWithNameSpace})`);
ignoredTopicsRegexes.push(new RegExp(ignoredTopicRegex), new RegExp(ignoredTopicRegexWithNameSpace));
const ignoredTopics = adapter.config.ignoredTopics?.split(',') ?? [];
for (const ignoredTopicPattern of ignoredTopics) {
if(!ignoredTopicPattern) {
// Empty strings would filter out all topics, which is probably not what the user wants
ignoredTopics.length > 1 && adapter.log.warn(`Ignored topics should not end with an ",".`);
continue;
}
const ignoredTopicRegexWithNameSpace = pattern2RegEx(`${adapter.namespace}.${ignoredTopicPattern}`, adapter);
const ignoredTopicRegex = pattern2RegEx(ignoredTopicPattern, adapter);
adapter.log.info(`Ignoring topic with pattern: ${ignoredTopicPattern} (RegExp: ${ignoredTopicRegex} und ${ignoredTopicRegexWithNameSpace})`);
ignoredTopicsRegexes.push(new RegExp(ignoredTopicRegex), new RegExp(ignoredTopicRegexWithNameSpace));
}


Expand Down
18 changes: 11 additions & 7 deletions lib/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,16 +36,20 @@ function MQTTServer(adapter, states) {
const verifiedObjects = {};

const ignoredTopicsRegexes = [];
if(adapter.config.ignoredTopics) {
const ignoredTopics = adapter.config.ignoredTopics.split(',');
for (const ignoredTopicPattern of ignoredTopics) {
const ignoredTopicRegexWithNameSpace = pattern2RegEx(`${adapter.namespace}.${ignoredTopicPattern}`, adapter);
const ignoredTopicRegex = pattern2RegEx(ignoredTopicPattern, adapter);
adapter.log.info(`Ignoring topic with pattern: ${ignoredTopicPattern} (RegExp: ${ignoredTopicRegex} und ${ignoredTopicRegexWithNameSpace})`);
ignoredTopicsRegexes.push(new RegExp(ignoredTopicRegex), new RegExp(ignoredTopicRegexWithNameSpace));
const ignoredTopics = adapter.config.ignoredTopics?.split(',') ?? [];
for (const ignoredTopicPattern of ignoredTopics) {
if(!ignoredTopicPattern) {
// Empty strings would filter out all topics, which is probably not what the user wants
ignoredTopics.length > 1 && adapter.log.warn(`Ignored topics should not end with an ",".`);
continue;
}
const ignoredTopicRegexWithNameSpace = pattern2RegEx(`${adapter.namespace}.${ignoredTopicPattern}`, adapter);
const ignoredTopicRegex = pattern2RegEx(ignoredTopicPattern, adapter);
adapter.log.info(`Ignoring topic with pattern: ${ignoredTopicPattern} (RegExp: ${ignoredTopicRegex} und ${ignoredTopicRegexWithNameSpace})`);
ignoredTopicsRegexes.push(new RegExp(ignoredTopicRegex), new RegExp(ignoredTopicRegexWithNameSpace));
}


adapter.config.sendOnStartInterval = parseInt(adapter.config.sendOnStartInterval, 10) || 2000;
adapter.config.sendInterval = parseInt(adapter.config.sendInterval, 10) || 0;

Expand Down
Loading