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

Allow subscriptions for complete sitemaps (not limited to a single page) #3652

Merged
merged 20 commits into from
May 1, 2024

Conversation

TAKeanice
Copy link
Contributor

@TAKeanice TAKeanice commented Jun 12, 2023

The changes in this PR allow to leave out the pageId in a request for updates from a subscription. The motivation for this was discussed in #3650

Leaving out the pageId in a subscription request makes the event API send events for updates of all widgets within a sitemap. This is accomplished by walking the sitemap tree and collecting all widgets in it when the subscription is created. Previously, only the widgets on the given page were collected at that occasion.

In the issue above, performance issues were discussed. I do not know how to test for them, and would happily accept help with that matter.

@TAKeanice TAKeanice requested a review from a team as a code owner June 12, 2023 00:12
@TAKeanice TAKeanice marked this pull request as draft June 12, 2023 00:12
@TAKeanice TAKeanice force-pushed the complete-sitemap-subscriptions branch 2 times, most recently from 12466df to 537b962 Compare June 12, 2023 05:21
@TAKeanice TAKeanice marked this pull request as ready for review June 12, 2023 06:27
@lolodomo
Copy link
Contributor

lolodomo commented Oct 21, 2023

I will have a look to your proposal. But as this is something we are not recommending at all, first can you confirm that this will not become the default behaviour for existing UIs ? And I would like something added in the javadoc explaining that this is a possible not a recommended usage.
Any official openHAB should not use that. This could lead to a massive network traffic between server and browser (SSE events).

@TAKeanice TAKeanice force-pushed the complete-sitemap-subscriptions branch 5 times, most recently from ce26ee9 to ac1f2f1 Compare November 12, 2023 17:05
@TAKeanice
Copy link
Contributor Author

TAKeanice commented Nov 12, 2023

@lolodomo thank you for giving this PR some support. I split up the methods to create a sitemap-wide subscription and a normal subscription endpoint, and wrote comments on the ones that should not be used. There should be no possibility to unconsciously subscribe to the whole sitemap.

The things I did not change apparently contained some nullability issues with the pageId. I did not try to resolve them to not break legacy behaviour.

@TAKeanice TAKeanice force-pushed the complete-sitemap-subscriptions branch 2 times, most recently from f5aa752 to 7fb7a18 Compare February 24, 2024 21:02
@TAKeanice TAKeanice force-pushed the complete-sitemap-subscriptions branch from 7fb7a18 to 4635625 Compare February 24, 2024 21:34
additionally refactor the test by removing redundancy

Signed-off-by: Tassilo Karge <[email protected]>
@TAKeanice
Copy link
Contributor Author

@lolodomo the compliance with your request to make sure not the whole sitemap is listened to by default is now also ensured by a regression test. I don´t see any reason why this should not be merged.

@TAKeanice
Copy link
Contributor Author

@lolodomo I know everyone is busy and stuff, but now that it´s spring and everything is getting back to life, would you consider reviving your interest in this PR, too?

Copy link
Member

@J-N-K J-N-K left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you can simplify the code very much by allowig pageId to be null (and consider that as "whole sitemap"). You can remove nearly all added methods in this case.

@TAKeanice
Copy link
Contributor Author

TAKeanice commented Apr 28, 2024

@J-N-K I the request by @lolodomo was specifically not to do that, since it could accidentally be used in some official implementation. My original implementation was like you suggested. If you want, I revert my changes to get that version back. Expecting your final decision :)

@J-N-K
Copy link
Member

J-N-K commented Apr 28, 2024

I can't find that request in this PR, can you point me to the comment?

@TAKeanice
Copy link
Contributor Author

the comment

#3652 (comment)_

Have I misinterpreted the request to make sure it does not get used accidentally?

@J-N-K
Copy link
Member

J-N-K commented Apr 28, 2024

IMO yes, my understanding is that a comment should state "whole sitemap is not recommended" (maybe also in the API documentation, not only in JavaDoc) and that a subscription with page should never result in a subscription to the whole sitemap.

But maybe @lolodomo can comment on this.

Edit: This only relevant for the SitemapResource, it does is not relevant for internal code. If omitting pageId for the "whole sitemap subscription" would be a good idea is debatable, but as far as I can see that is not possible in any case, because it would collide with other endpoints. Accidentally adding * or wholeSitemap will not happen.

@TAKeanice
Copy link
Contributor Author

I will make some simplifications to the private methods, that should reduce code duplication.

@lolodomo
Copy link
Contributor

lolodomo commented Apr 28, 2024

IMO yes, my understanding is that a comment should state "whole sitemap is not recommended"

Yes, exactly ,that was my request.
Also as a consequence that it should not become the default behaviour.

@TAKeanice
Copy link
Contributor Author

The reason I split the methods is that the method getSitemapEvents

public void getSitemapEvents(@Context final SseEventSink sseEventSink, @Context final HttpServletResponse response,
@PathParam("subscriptionid") @Parameter(description = "subscription id") String subscriptionId,
@QueryParam("sitemap") @Parameter(description = "sitemap name") @Nullable String sitemapname,
@QueryParam("pageid") @Parameter(description = "page id") @Nullable String pageId) {
allows null as pageId. If I unsplit the whole implementation by allowing null pageIds throughout, omitting the pageId when calling that method would result in accidentally using sitemap-wide subscriptions. That was the nullability issue I referred to here: #3652 (comment)

@J-N-K
Copy link
Member

J-N-K commented May 1, 2024

There is an issue with the tests, can you fix that? I'll nmerge afterwards. Thanks for your patience.

@lolodomo
Copy link
Contributor

lolodomo commented May 1, 2024

I have not checked but I will not be surprised that tests are failing due to the change I am commenting in my last message.

@TAKeanice
Copy link
Contributor Author

@J-N-K and @lolodomo I think the tests fail due to my code deduplication, I'll fix that today. It was a pleasure working on finalizing this the last couple of days, thank you for that!

@TAKeanice
Copy link
Contributor Author

The test fails because the subscriptionService is just a mock, I need to properly instantiate it and mock its itemUIRegistry in the test.

@J-N-K
Copy link
Member

J-N-K commented May 1, 2024

You can also keep the mocked subscriptionService and return another mock, depending on the called method (using when).

@TAKeanice
Copy link
Contributor Author

You can also keep the mocked subscriptionService

but that would defeat the purpose of the test, since an important part of the logic resides in collectWidgets

@J-N-K
Copy link
Member

J-N-K commented May 1, 2024

I didn't look at the test, it was more a general comment.

Signed-off-by: Tassilo Karge <[email protected]>
Copy link
Member

@J-N-K J-N-K left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@J-N-K J-N-K added the enhancement An enhancement or new feature of the Core label May 1, 2024
@J-N-K J-N-K added this to the 4.2 milestone May 1, 2024
@J-N-K J-N-K merged commit c430e6f into openhab:main May 1, 2024
5 checks passed
@J-N-K J-N-K changed the title Improvement: Allow subscriptions for complete sitemaps (not limited to a single page) Allow subscriptions for complete sitemaps (not limited to a single page) May 1, 2024
@TAKeanice
Copy link
Contributor Author

@J-N-K the test issues have been resolved.

@lolodomo
Copy link
Contributor

lolodomo commented May 2, 2024

By renaming method setPageId, you broke UIs using it :(
Basic UI is no more compiling, I am going to fix that.

lolodomo added a commit to lolodomo/openhab-webui that referenced this pull request May 2, 2024
Related to openhab/openhab-core#3652 that renamed method setPageId into updateSubscriptionLocation

Signed-off-by: Laurent Garnier <[email protected]>
florian-h05 pushed a commit to openhab/openhab-webui that referenced this pull request May 2, 2024
Related to openhab/openhab-core#3652 that renamed method setPageId into
updateSubscriptionLocation

Signed-off-by: Laurent Garnier <[email protected]>
@TAKeanice
Copy link
Contributor Author

I am going to fix that.

Thank you very much, I wasn't aware that the method was public api. Maybe I should re-add the legacy method but deprecate it and make it just call the new one, just in case other (plugin) implementations use the method, too?

@lolodomo
Copy link
Contributor

lolodomo commented May 2, 2024

I searched in GitHub (including iOS and Android apps) and apparently Basic UI was the unique app calling this method.

@lolodomo
Copy link
Contributor

lolodomo commented May 2, 2024

But you could fix javadoc still referencing it

* For this to work correctly, the subscriber needs to make sure that setPageId is called whenever it switches to a new

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement An enhancement or new feature of the Core REST/SSE sitemap
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants