* Removing some other fake apps

* More FakeApp removed

* Removing entirely FakeApp

* Fixing some tests

* Fixing get Cluster id from get plugin status

* Fixing failing tests

* Fixing tests

* Fixing test initialization for web

* Fixing InitServer for server tests

* Fixing InitServer for server tests

* Reverting go.sum and go.mod

* Removing unneded HTMLTemplates function in App layer

* Moving back some functions to its old place to easy the review

* Moving back some functions to its old place to easy the review

* Using the last struct2interface version

* Generating store layers

* Fixing merge problems

* Addressing PR comments

* Small fix

* Fixing app tests build

* Fixing tests

* fixing tests

* Fix tests

* Fixing tests

* Fixing tests

* Fixing tests

* Moving license to server struct

* Adding some fixes to the test compilation

* Fixing cluster and some jobs initialization

* Fixing some license tests compilation problems

* Fixing recursive cache invalidation

* Regenerating app layers

* Fix test compilation

Co-authored-by: mattermod <mattermod@users.noreply.github.com>
Этот коммит содержится в:
Jesús Espino
2020-06-12 13:43:50 +02:00
коммит произвёл GitHub
родитель f3ac33e6dc
Коммит f5eab1271b
88 изменённых файлов: 973 добавлений и 1177 удалений

Просмотреть файл

@@ -96,19 +96,6 @@ func (a *App) HubStart() {
}
}
func (a *App) PublishSkipClusterSend(message *model.WebSocketEvent) {
if message.GetBroadcast().UserId != "" {
hub := a.GetHubForUserId(message.GetBroadcast().UserId)
if hub != nil {
hub.Broadcast(message)
}
return
}
for _, hub := range a.Srv().GetHubs() {
hub.Broadcast(message)
}
}
func (a *App) invalidateCacheForUserSkipClusterSend(userId string) {
a.Srv().Store.Channel().InvalidateAllChannelMembersForUser(userId)
a.InvalidateWebConnSessionCacheForUser(userId)
@@ -126,26 +113,30 @@ func (a *App) InvalidateWebConnSessionCacheForUser(userId string) {
}
// HubStop stops all the hubs.
func (a *App) HubStop() {
func (s *Server) HubStop() {
mlog.Info("stopping websocket hub connections")
for _, hub := range a.Srv().GetHubs() {
for _, hub := range s.GetHubs() {
hub.Stop()
}
a.Srv().SetHubs([]*Hub{})
s.SetHubs([]*Hub{})
}
func (a *App) HubStop() {
a.Srv().HubStop()
}
// GetHubForUserId returns the hub for a given user id.
func (a *App) GetHubForUserId(userId string) *Hub {
if len(a.Srv().GetHubs()) == 0 {
func (s *Server) GetHubForUserId(userId string) *Hub {
if len(s.GetHubs()) == 0 {
return nil
}
hash := fnv.New32a()
hash.Write([]byte(userId))
index := hash.Sum32() % uint32(len(a.Srv().GetHubs()))
hub, err := a.Srv().GetHub(int(index))
index := hash.Sum32() % uint32(len(s.GetHubs()))
hub, err := s.GetHub(int(index))
if err != nil {
mlog.Warn("Requested hub doesn't exist", mlog.Int("hub_index", int(index)))
return nil
@@ -153,6 +144,10 @@ func (a *App) GetHubForUserId(userId string) *Hub {
return hub
}
func (a *App) GetHubForUserId(userId string) *Hub {
return a.Srv().GetHubForUserId(userId)
}
// HubRegister registers a connection to a hub.
func (a *App) HubRegister(webConn *WebConn) {
hub := a.GetHubForUserId(webConn.UserId)
@@ -175,14 +170,14 @@ func (a *App) HubUnregister(webConn *WebConn) {
}
}
func (a *App) Publish(message *model.WebSocketEvent) {
if metrics := a.Metrics(); metrics != nil {
metrics.IncrementWebsocketEvent(message.EventType())
func (s *Server) Publish(message *model.WebSocketEvent) {
if s.Metrics != nil {
s.Metrics.IncrementWebsocketEvent(message.EventType())
}
a.PublishSkipClusterSend(message)
s.PublishSkipClusterSend(message)
if a.Cluster() != nil {
if s.Cluster != nil {
cm := &model.ClusterMessage{
Event: model.CLUSTER_EVENT_PUBLISH,
SendType: model.CLUSTER_SEND_BEST_EFFORT,
@@ -197,10 +192,31 @@ func (a *App) Publish(message *model.WebSocketEvent) {
cm.SendType = model.CLUSTER_SEND_RELIABLE
}
a.Cluster().SendClusterMessage(cm)
s.Cluster.SendClusterMessage(cm)
}
}
func (a *App) Publish(message *model.WebSocketEvent) {
a.Srv().Publish(message)
}
func (s *Server) PublishSkipClusterSend(message *model.WebSocketEvent) {
if message.GetBroadcast().UserId != "" {
hub := s.GetHubForUserId(message.GetBroadcast().UserId)
if hub != nil {
hub.Broadcast(message)
}
} else {
for _, hub := range s.GetHubs() {
hub.Broadcast(message)
}
}
}
func (a *App) PublishSkipClusterSend(message *model.WebSocketEvent) {
a.Srv().PublishSkipClusterSend(message)
}
func (a *App) invalidateCacheForChannel(channel *model.Channel) {
a.Srv().Store.Channel().InvalidateChannel(channel.Id)
a.invalidateCacheForChannelByNameSkipClusterSend(channel.TeamId, channel.Name)