-
-
Notifications
You must be signed in to change notification settings - Fork 429
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
Fix reloading channel config changes in .items file #4075
Conversation
Changes in channel config weren't applied because ItemChannelLink.equals() include the link configurations in the comparison. This caused the new link not being found in the set lookup, which leads to erroneously calling notifyListenersAboutAddedElement, when it should've called notifyListenersAboutUpdatedElement instead. Signed-off-by: Jimmy Tanagra <jcode@tanagra.id.au>
This pull request has been mentioned on openHAB Community. There might be relevant details there: https://community.openhab.org/t/problems-at-reducing-item-changes-with-regex/153400/13 |
This pull request has been mentioned on openHAB Community. There might be relevant details there: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thanks. (I’m no core maintainer though.)
I think I experienced that issue when attempting to set up a JS transformation for a channel link and I wanted to either open an issue or look into that myself, but you have already solved the problem, great!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Otherwise LGTM. Nice finding.
if (links == null) { | ||
itemChannelLinkMap.put(itemName, links = new HashSet<>()); | ||
itemChannelLinkMap.put(itemName, links = new HashMap<>(2)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
itemChannelLinkMap.put(itemName, links = new HashMap<>(2)); | |
itemChannelLinkMap.put(itemName, links = new HashMap<>(2)); |
Why 2
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The default is 16 with .75 load factor. That seems like a waste of memory because most items have just one link.
If I set it to one, as soon as one element is added, it would trigger a rehash and capacity expansion anyway, because it would have exceeded the load factor. So 2 is chosen here.
Tbh this is just a guess based on reading about the description of initial capacity and load factor from hashmap's doc. I haven't done actual memory analysis tests to verify.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've added a comment in the code for future reference
for (ItemChannelLink removedItemChannelLink : links.values()) { | ||
notifyListenersAboutRemovedElement(removedItemChannelLink); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
for (ItemChannelLink removedItemChannelLink : links.values()) { | |
notifyListenersAboutRemovedElement(removedItemChannelLink); | |
} | |
links.values().forEach(this::notifyListenersAboutRemovedElement); |
Signed-off-by: Jimmy Tanagra <jcode@tanagra.id.au>
Signed-off-by: Jimmy Tanagra <jcode@tanagra.id.au>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
Apply channel config changes in .items file
Changes in channel config weren't applied because ItemChannelLink.equals() include the link configurations in the comparison. This caused the new link not being found in the set lookup, which leads to erroneously calling notifyListenersAboutAddedElement, when it should've called notifyListenersAboutUpdatedElement instead.
The problem that this PR fixes:
Changing channel config in an .items file, e.g. only the
function
is being changed from:to:
This wouldn't take effect unless a more severe measure was taken, e.g. commenting out the item and re-adding it, or in many cases, users would restart openHAB to reload such changes.
Reported here:
https://community.openhab.org/t/problems-at-reducing-item-changes-with-regex/153400/6
Related:
#3235
This problem may have been started / caused by #1794
Note: I've set the initial capacity for the hashmap to 2, because most items only have 1 link, hopefully it saves a bit of memory by not pre-allocating for 16 slots by default.