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

Refresh button when branch changes #20511

Open
wants to merge 8 commits into
base: main
Choose a base branch
from

Conversation

maxbol
Copy link

@maxbol maxbol commented Jul 27, 2022

Fixes #18427

Had a quick go at the problem. Events are sent at the end of hook_post_receive.go, to all users returned by access_model.GetRepoReaders() for the updated repo. The FE event handler filters incoming events by owner, repo and branch. Both changes to the base and head target triggers the reveal of the refresh button.

Working good as far as I can tell, some more polish might be needed.

Questions:

  • Should there be a polling fallback for this behavior if EventSource is not available in the browser?
  • What color and position should be used for the button?
  • Is the behavior displayed exactly the one discussed in the original issue, or did I miss something?
  • Are all service workers supposed to use notification-worker for their name? Seemed to be the case in both the currently existing ones, so I followed that example... not sure if it makes sense or not.

Please give me your feedback!

EDIT: Removed WIP label

@Gusted Gusted added this to the 1.18.0 milestone Jul 28, 2022
@silverwind
Copy link
Member

silverwind commented Jul 28, 2022

Could it be that we are generally doing SharedWorker wrong by creating a separate one for each event type? I think there should likely be only one worker thread that handles all events and JS should distinguish these events by a type property in the sent data.

@GiteaBot GiteaBot added the lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. label Jul 28, 2022
@maxbol
Copy link
Author

maxbol commented Jul 28, 2022

Could it be that we are generally doing SharedWorker wrong by creating a separate one for each event type? I think there should likely be only one worker thread that handles all events and JS should distinguish these events by a type property in the sent data.

This was my thought as well.

EDIT: And the type property is already there, so it should enough to instantiate the SharedWorker as a singleton in a separate file and import it where it's needed.

@maxbol maxbol changed the title WIP: Refresh button when branch changes Refresh button when branch changes Jul 29, 2022
@maxbol
Copy link
Author

maxbol commented Jul 29, 2022

Refactored the use of SharedWorker per @silverwind s suggestion:

1d71ee6

Gonna go ahead and remove the WIP label from this, as I think it successfully addresses the original feature request. If there is anything missing from this solution, please let me know!

@silverwind
Copy link
Member

@zeripath what should we do with this in regards to #20543?

@zeripath
Copy link
Contributor

First off thanks for the PR.

But as far as I can see the current code would inform any logged user of updates to any branch in any repo. This is a huge security hole. At the very least you need to check if the repo can be seen by the user before you push it up their eventstream but its still a huge amount of events that are not needed and this is why I think this problem needs a different approach using websocket to register which repo and branch you're actually interested in.

I'm not sure I understand the restructuring that has occurred in the JS (I'm on my phone) but it looks to me like it's still using the eventstream that was originally there.

@silverwind
Copy link
Member

I too think we should probably just move everything to websocket, completely removing EventSource.

@zeripath
Copy link
Contributor

Well if you can figure out why the Dom isn't updating in my WIP PR we can get going with that but right now although I have a working websocket that is producing the eventstream events and thus could replace the event source, the events won't update the webpage.

@maxbol
Copy link
Author

maxbol commented Jul 30, 2022

But as far as I can see the current code would inform any logged user of updates to any branch in any repo.

Maybe I've misunderstood some part of the access model, but isn't this restricted by access_model.GetRepoReaders() here:

https://github.com/go-gitea/gitea/pull/20511/files#diff-4e06ddb19de4d68ed031e1381dc794902f732ae8a731192d00b5869b311a1601R53

It should literally only send events to users who have read access to the repo, no?

@maxbol
Copy link
Author

maxbol commented Jul 30, 2022

With regards to websockets vs SSE, I have no horse in that race - just responding to the original feature request and bounty, which clearly separated the issues: #18427 (comment)

Although I'm not entirely certain what pros websockets (a bidirectional, stateful stream) have over SSE here. SSE seems to generally fit the pattern of an original, client-initiated request to setup a unidirectional flow from server to client better. And HTTP/2 makes WS obsolete. Maybe just refactor the EventSource module somewhat server side so you can use other targets than uids (like for instance repos, refnames or orgs). Authorization could then be handled on subscription, when the client initiates the request, or something like that.

@maxbol
Copy link
Author

maxbol commented Oct 11, 2022 via email

@yardenshoham yardenshoham added the type/feature Completely new functionality. Can only be merged if feature freeze is not active. label Oct 23, 2022
@lunny
Copy link
Member

lunny commented Oct 25, 2022

SendMessage via event source will not always work within multiple replication Gitea system. So I think we need a redis based abstract layer to do that. Let's move this to next release to think more.

@lunny lunny modified the milestones: 1.18.0, 1.19.0 Oct 25, 2022
@silverwind
Copy link
Member

silverwind commented Dec 6, 2022

SendMessage via event source will not always work within multiple replication Gitea system. So I think we need a redis based abstract layer to do that. Let's move this to next release to think more.

What could be done is have all servers being SUBSCRIBEd to a certain redis/kafka/etc channel, and the server that wants to send the message PUBLISHes it to the channel, after which all servers including the sender receive the message and send it on to all their connected and/or affected clients.

I think such an approach is universal for server-to-client communication in distributed setups. Ideally this would be done via websockets, thought.

@lafriks
Copy link
Member

lafriks commented Dec 6, 2022

Would be good if such subscription/event model would be made abstract like we have with queues so that multiple types of subscription providers can be implemented as at least both internal (default) and redis could be used for this.

@jolheiser jolheiser modified the milestones: 1.19.0, 1.20.0 Jan 31, 2023
@delvh delvh removed this from the 1.20.0 milestone Jun 4, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. type/feature Completely new functionality. Can only be merged if feature freeze is not active.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[FEATURE] Refresh button when branch changes
10 participants