Removing some unneded FakeApp instance (#14139)

Этот коммит содержится в:
Jesús Espino
2020-03-27 14:52:57 +01:00
коммит произвёл GitHub
родитель cfe65a33a5
Коммит 9a531fa0fb
8 изменённых файлов: 85 добавлений и 92 удалений

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

@@ -78,16 +78,16 @@ func (a *App) configOrLicenseListener() {
func (s *Server) initJobs() { func (s *Server) initJobs() {
s.Jobs = jobs.NewJobServer(s, s.Store) s.Jobs = jobs.NewJobServer(s, s.Store)
if jobsDataRetentionJobInterface != nil { if jobsDataRetentionJobInterface != nil {
s.Jobs.DataRetentionJob = jobsDataRetentionJobInterface(s.FakeApp()) s.Jobs.DataRetentionJob = jobsDataRetentionJobInterface(s)
} }
if jobsMessageExportJobInterface != nil { if jobsMessageExportJobInterface != nil {
s.Jobs.MessageExportJob = jobsMessageExportJobInterface(s.FakeApp()) s.Jobs.MessageExportJob = jobsMessageExportJobInterface(s)
} }
if jobsElasticsearchAggregatorInterface != nil { if jobsElasticsearchAggregatorInterface != nil {
s.Jobs.ElasticsearchAggregator = jobsElasticsearchAggregatorInterface(s.FakeApp()) s.Jobs.ElasticsearchAggregator = jobsElasticsearchAggregatorInterface(s)
} }
if jobsElasticsearchIndexerInterface != nil { if jobsElasticsearchIndexerInterface != nil {
s.Jobs.ElasticsearchIndexer = jobsElasticsearchIndexerInterface(s.FakeApp()) s.Jobs.ElasticsearchIndexer = jobsElasticsearchIndexerInterface(s)
} }
if jobsLdapSyncInterface != nil { if jobsLdapSyncInterface != nil {
s.Jobs.LdapSync = jobsLdapSyncInterface(s.FakeApp()) s.Jobs.LdapSync = jobsLdapSyncInterface(s.FakeApp())
@@ -110,25 +110,6 @@ func (a *App) SetDiagnosticId(id string) {
a.Srv().diagnosticId = id a.Srv().diagnosticId = id
} }
func (a *App) EnsureDiagnosticId() {
if a.Srv().diagnosticId != "" {
return
}
props, err := a.Srv().Store.System().Get()
if err != nil {
return
}
id := props[model.SYSTEM_DIAGNOSTIC_ID]
if len(id) == 0 {
id = model.NewId()
systemId := &model.System{Name: model.SYSTEM_DIAGNOSTIC_ID, Value: id}
a.Srv().Store.System().Save(systemId)
}
a.Srv().diagnosticId = id
}
func (a *App) HTMLTemplates() *template.Template { func (a *App) HTMLTemplates() *template.Template {
if a.Srv().htmlTemplateWatcher != nil { if a.Srv().htmlTemplateWatcher != nil {
return a.Srv().htmlTemplateWatcher.Templates() return a.Srv().htmlTemplateWatcher.Templates()

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

@@ -411,7 +411,6 @@ type AppIface interface {
DoUploadFileExpectModification(now time.Time, rawTeamId string, rawChannelId string, rawUserId string, rawFilename string, data []byte) (*model.FileInfo, []byte, *model.AppError) DoUploadFileExpectModification(now time.Time, rawTeamId string, rawChannelId string, rawUserId string, rawFilename string, data []byte) (*model.FileInfo, []byte, *model.AppError)
DownloadFromURL(downloadURL string) ([]byte, error) DownloadFromURL(downloadURL string) ([]byte, error)
EnableUserAccessToken(token *model.UserAccessToken) *model.AppError EnableUserAccessToken(token *model.UserAccessToken) *model.AppError
EnsureDiagnosticId()
EnvironmentConfig() map[string]interface{} EnvironmentConfig() map[string]interface{}
// @openTracingParams args // @openTracingParams args
ExecuteCommand(args *model.CommandArgs) (*model.CommandResponse, *model.AppError) ExecuteCommand(args *model.CommandArgs) (*model.CommandResponse, *model.AppError)

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

@@ -24,45 +24,45 @@ func RegisterClusterInterface(f func(*Server) einterfaces.ClusterInterface) {
clusterInterface = f clusterInterface = f
} }
var complianceInterface func(*App) einterfaces.ComplianceInterface var complianceInterface func(*Server) einterfaces.ComplianceInterface
func RegisterComplianceInterface(f func(*App) einterfaces.ComplianceInterface) { func RegisterComplianceInterface(f func(*Server) einterfaces.ComplianceInterface) {
complianceInterface = f complianceInterface = f
} }
var dataRetentionInterface func(*App) einterfaces.DataRetentionInterface var dataRetentionInterface func(*Server) einterfaces.DataRetentionInterface
func RegisterDataRetentionInterface(f func(*App) einterfaces.DataRetentionInterface) { func RegisterDataRetentionInterface(f func(*Server) einterfaces.DataRetentionInterface) {
dataRetentionInterface = f dataRetentionInterface = f
} }
var elasticsearchInterface func(*App) searchengine.SearchEngineInterface var elasticsearchInterface func(*Server) searchengine.SearchEngineInterface
func RegisterElasticsearchInterface(f func(*App) searchengine.SearchEngineInterface) { func RegisterElasticsearchInterface(f func(*Server) searchengine.SearchEngineInterface) {
elasticsearchInterface = f elasticsearchInterface = f
} }
var jobsDataRetentionJobInterface func(*App) ejobs.DataRetentionJobInterface var jobsDataRetentionJobInterface func(*Server) ejobs.DataRetentionJobInterface
func RegisterJobsDataRetentionJobInterface(f func(*App) ejobs.DataRetentionJobInterface) { func RegisterJobsDataRetentionJobInterface(f func(*Server) ejobs.DataRetentionJobInterface) {
jobsDataRetentionJobInterface = f jobsDataRetentionJobInterface = f
} }
var jobsMessageExportJobInterface func(*App) ejobs.MessageExportJobInterface var jobsMessageExportJobInterface func(*Server) ejobs.MessageExportJobInterface
func RegisterJobsMessageExportJobInterface(f func(*App) ejobs.MessageExportJobInterface) { func RegisterJobsMessageExportJobInterface(f func(*Server) ejobs.MessageExportJobInterface) {
jobsMessageExportJobInterface = f jobsMessageExportJobInterface = f
} }
var jobsElasticsearchAggregatorInterface func(*App) ejobs.ElasticsearchAggregatorInterface var jobsElasticsearchAggregatorInterface func(*Server) ejobs.ElasticsearchAggregatorInterface
func RegisterJobsElasticsearchAggregatorInterface(f func(*App) ejobs.ElasticsearchAggregatorInterface) { func RegisterJobsElasticsearchAggregatorInterface(f func(*Server) ejobs.ElasticsearchAggregatorInterface) {
jobsElasticsearchAggregatorInterface = f jobsElasticsearchAggregatorInterface = f
} }
var jobsElasticsearchIndexerInterface func(*App) ejobs.ElasticsearchIndexerInterface var jobsElasticsearchIndexerInterface func(*Server) ejobs.ElasticsearchIndexerInterface
func RegisterJobsElasticsearchIndexerInterface(f func(*App) ejobs.ElasticsearchIndexerInterface) { func RegisterJobsElasticsearchIndexerInterface(f func(*Server) ejobs.ElasticsearchIndexerInterface) {
jobsElasticsearchIndexerInterface = f jobsElasticsearchIndexerInterface = f
} }
@@ -90,15 +90,15 @@ func RegisterLdapInterface(f func(*App) einterfaces.LdapInterface) {
ldapInterface = f ldapInterface = f
} }
var messageExportInterface func(*App) einterfaces.MessageExportInterface var messageExportInterface func(*Server) einterfaces.MessageExportInterface
func RegisterMessageExportInterface(f func(*App) einterfaces.MessageExportInterface) { func RegisterMessageExportInterface(f func(*Server) einterfaces.MessageExportInterface) {
messageExportInterface = f messageExportInterface = f
} }
var metricsInterface func(*App) einterfaces.MetricsInterface var metricsInterface func(*Server) einterfaces.MetricsInterface
func RegisterMetricsInterface(f func(*App) einterfaces.MetricsInterface) { func RegisterMetricsInterface(f func(*Server) einterfaces.MetricsInterface) {
metricsInterface = f metricsInterface = f
} }
@@ -122,19 +122,19 @@ func RegisterNotificationInterface(f func(*App) einterfaces.NotificationInterfac
func (s *Server) initEnterprise() { func (s *Server) initEnterprise() {
if metricsInterface != nil { if metricsInterface != nil {
s.Metrics = metricsInterface(s.FakeApp()) s.Metrics = metricsInterface(s)
} }
if accountMigrationInterface != nil { if accountMigrationInterface != nil {
s.AccountMigration = accountMigrationInterface(s) s.AccountMigration = accountMigrationInterface(s)
} }
if complianceInterface != nil { if complianceInterface != nil {
s.Compliance = complianceInterface(s.FakeApp()) s.Compliance = complianceInterface(s)
} }
if ldapInterface != nil { if ldapInterface != nil {
s.Ldap = ldapInterface(s.FakeApp()) s.Ldap = ldapInterface(s.FakeApp())
} }
if messageExportInterface != nil { if messageExportInterface != nil {
s.MessageExport = messageExportInterface(s.FakeApp()) s.MessageExport = messageExportInterface(s)
} }
if notificationInterface != nil { if notificationInterface != nil {
s.Notification = notificationInterface(s.FakeApp()) s.Notification = notificationInterface(s.FakeApp())
@@ -154,13 +154,13 @@ func (s *Server) initEnterprise() {
}) })
} }
if dataRetentionInterface != nil { if dataRetentionInterface != nil {
s.DataRetention = dataRetentionInterface(s.FakeApp()) s.DataRetention = dataRetentionInterface(s)
} }
if clusterInterface != nil { if clusterInterface != nil {
s.Cluster = clusterInterface(s) s.Cluster = clusterInterface(s)
} }
if elasticsearchInterface != nil { if elasticsearchInterface != nil {
s.SearchEngine.RegisterElasticsearchEngine(elasticsearchInterface(s.FakeApp())) s.SearchEngine.RegisterElasticsearchEngine(elasticsearchInterface(s))
} }
} }

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

@@ -69,8 +69,7 @@ const (
) )
func (a *App) FileBackend() (filesstore.FileBackend, *model.AppError) { func (a *App) FileBackend() (filesstore.FileBackend, *model.AppError) {
license := a.License() return a.Srv().FileBackend()
return filesstore.NewFileBackend(&a.Config().FileSettings, license != nil && *license.Features.Compliance)
} }
func (a *App) ReadFile(path string) ([]byte, *model.AppError) { func (a *App) ReadFile(path string) ([]byte, *model.AppError) {

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

@@ -3234,21 +3234,6 @@ func (a *OpenTracingAppLayer) EnableUserAccessToken(token *model.UserAccessToken
return resultVar0 return resultVar0
} }
func (a *OpenTracingAppLayer) EnsureDiagnosticId() {
origCtx := a.ctx
span, newCtx := tracing.StartSpanWithParentByContext(a.ctx, "app.EnsureDiagnosticId")
a.ctx = newCtx
a.app.Srv().Store.SetContext(newCtx)
defer func() {
a.app.Srv().Store.SetContext(origCtx)
a.ctx = origCtx
}()
defer span.Finish()
a.app.EnsureDiagnosticId()
}
func (a *OpenTracingAppLayer) EnvironmentConfig() map[string]interface{} { func (a *OpenTracingAppLayer) EnvironmentConfig() map[string]interface{} {
origCtx := a.ctx origCtx := a.ctx
span, newCtx := tracing.StartSpanWithParentByContext(a.ctx, "app.EnvironmentConfig") span, newCtx := tracing.StartSpanWithParentByContext(a.ctx, "app.EnvironmentConfig")

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

@@ -33,6 +33,7 @@ import (
"github.com/mattermost/mattermost-server/v5/plugin" "github.com/mattermost/mattermost-server/v5/plugin"
"github.com/mattermost/mattermost-server/v5/services/cache" "github.com/mattermost/mattermost-server/v5/services/cache"
"github.com/mattermost/mattermost-server/v5/services/cache/lru" "github.com/mattermost/mattermost-server/v5/services/cache/lru"
"github.com/mattermost/mattermost-server/v5/services/filesstore"
"github.com/mattermost/mattermost-server/v5/services/httpservice" "github.com/mattermost/mattermost-server/v5/services/httpservice"
"github.com/mattermost/mattermost-server/v5/services/imageproxy" "github.com/mattermost/mattermost-server/v5/services/imageproxy"
"github.com/mattermost/mattermost-server/v5/services/searchengine" "github.com/mattermost/mattermost-server/v5/services/searchengine"
@@ -202,7 +203,7 @@ func NewServer(options ...Option) (*Server, error) {
s.NotificationsLog.ChangeLevels(utils.MloggerConfigFromLoggerConfig(notificationLogSettings, utils.GetNotificationsLogFileLocation)) s.NotificationsLog.ChangeLevels(utils.MloggerConfigFromLoggerConfig(notificationLogSettings, utils.GetNotificationsLogFileLocation))
}) })
s.HTTPService = httpservice.MakeHTTPService(s.FakeApp()) s.HTTPService = httpservice.MakeHTTPService(s)
s.ImageProxy = imageproxy.MakeImageProxy(s, s.HTTPService, s.Log) s.ImageProxy = imageproxy.MakeImageProxy(s, s.HTTPService, s.Log)
@@ -918,3 +919,36 @@ func (s *Server) SetHub(index int, hub *Hub) error {
s.hubs[index] = hub s.hubs[index] = hub
return nil return nil
} }
func (s *Server) FileBackend() (filesstore.FileBackend, *model.AppError) {
license := s.License()
return filesstore.NewFileBackend(&s.Config().FileSettings, license != nil && *license.Features.Compliance)
}
func (s *Server) TotalWebsocketConnections() int {
count := int64(0)
for _, hub := range s.GetHubs() {
count = count + atomic.LoadInt64(&hub.connectionCount)
}
return int(count)
}
func (s *Server) ensureDiagnosticId() {
if s.diagnosticId != "" {
return
}
props, err := s.Store.System().Get()
if err != nil {
return
}
id := props[model.SYSTEM_DIAGNOSTIC_ID]
if len(id) == 0 {
id = model.NewId()
systemID := &model.System{Name: model.SYSTEM_DIAGNOSTIC_ID, Value: id}
s.Store.System().Save(systemID)
}
s.diagnosticId = id
}

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

@@ -26,11 +26,11 @@ import (
func (s *Server) RunOldAppInitialization() error { func (s *Server) RunOldAppInitialization() error {
s.FakeApp().createPushNotificationsHub() s.FakeApp().createPushNotificationsHub()
if err := utils.InitTranslations(s.FakeApp().Config().LocalizationSettings); err != nil { if err := utils.InitTranslations(s.Config().LocalizationSettings); err != nil {
return errors.Wrapf(err, "unable to load Mattermost translation files") return errors.Wrapf(err, "unable to load Mattermost translation files")
} }
s.FakeApp().Srv().configListenerId = s.FakeApp().AddConfigListener(func(_, _ *model.Config) { s.configListenerId = s.AddConfigListener(func(_, _ *model.Config) {
s.FakeApp().configOrLicenseListener() s.FakeApp().configOrLicenseListener()
message := model.NewWebSocketEvent(model.WEBSOCKET_EVENT_CONFIG_CHANGED, "", "", "", nil) message := model.NewWebSocketEvent(model.WEBSOCKET_EVENT_CONFIG_CHANGED, "", "", "", nil)
@@ -40,7 +40,7 @@ func (s *Server) RunOldAppInitialization() error {
s.FakeApp().Publish(message) s.FakeApp().Publish(message)
}) })
}) })
s.FakeApp().Srv().licenseListenerId = s.FakeApp().AddLicenseListener(func(oldLicense, newLicense *model.License) { s.licenseListenerId = s.AddLicenseListener(func(oldLicense, newLicense *model.License) {
s.FakeApp().configOrLicenseListener() s.FakeApp().configOrLicenseListener()
message := model.NewWebSocketEvent(model.WEBSOCKET_EVENT_LICENSE_CHANGED, "", "", "", nil) message := model.NewWebSocketEvent(model.WEBSOCKET_EVENT_LICENSE_CHANGED, "", "", "", nil)
@@ -59,12 +59,12 @@ func (s *Server) RunOldAppInitialization() error {
s.initEnterprise() s.initEnterprise()
if s.FakeApp().Srv().newStore == nil { if s.newStore == nil {
s.FakeApp().Srv().newStore = func() store.Store { s.newStore = func() store.Store {
return store.NewTimerLayer( return store.NewTimerLayer(
searchlayer.NewSearchLayer( searchlayer.NewSearchLayer(
localcachelayer.NewLocalCacheLayer( localcachelayer.NewLocalCacheLayer(
sqlstore.NewSqlSupplier(s.FakeApp().Config().SqlSettings, s.Metrics), sqlstore.NewSqlSupplier(s.Config().SqlSettings, s.Metrics),
s.Metrics, s.Metrics,
s.Cluster, s.Cluster,
s.CacheProvider, s.CacheProvider,
@@ -79,10 +79,10 @@ func (s *Server) RunOldAppInitialization() error {
if htmlTemplateWatcher, err := utils.NewHTMLTemplateWatcher("templates"); err != nil { if htmlTemplateWatcher, err := utils.NewHTMLTemplateWatcher("templates"); err != nil {
mlog.Error("Failed to parse server templates", mlog.Err(err)) mlog.Error("Failed to parse server templates", mlog.Err(err))
} else { } else {
s.FakeApp().Srv().htmlTemplateWatcher = htmlTemplateWatcher s.htmlTemplateWatcher = htmlTemplateWatcher
} }
s.FakeApp().Srv().Store = s.FakeApp().Srv().newStore() s.Store = s.newStore()
s.FakeApp().StartPushNotificationsHubWorkers() s.FakeApp().StartPushNotificationsHubWorkers()
if err := s.FakeApp().ensureAsymmetricSigningKey(); err != nil { if err := s.FakeApp().ensureAsymmetricSigningKey(); err != nil {
@@ -97,49 +97,49 @@ func (s *Server) RunOldAppInitialization() error {
return errors.Wrapf(err, "unable to ensure installation date") return errors.Wrapf(err, "unable to ensure installation date")
} }
s.FakeApp().EnsureDiagnosticId() s.ensureDiagnosticId()
s.FakeApp().regenerateClientConfig() s.FakeApp().regenerateClientConfig()
s.FakeApp().Srv().clusterLeaderListenerId = s.FakeApp().Srv().AddClusterLeaderChangedListener(func() { s.clusterLeaderListenerId = s.AddClusterLeaderChangedListener(func() {
mlog.Info("Cluster leader changed. Determining if job schedulers should be running:", mlog.Bool("isLeader", s.FakeApp().IsLeader())) mlog.Info("Cluster leader changed. Determining if job schedulers should be running:", mlog.Bool("isLeader", s.FakeApp().IsLeader()))
if s.FakeApp().Srv().Jobs != nil { if s.Jobs != nil {
s.FakeApp().Srv().Jobs.Schedulers.HandleClusterLeaderChange(s.FakeApp().IsLeader()) s.Jobs.Schedulers.HandleClusterLeaderChange(s.FakeApp().IsLeader())
} }
}) })
subpath, err := utils.GetSubpathFromConfig(s.FakeApp().Config()) subpath, err := utils.GetSubpathFromConfig(s.Config())
if err != nil { if err != nil {
return errors.Wrap(err, "failed to parse SiteURL subpath") return errors.Wrap(err, "failed to parse SiteURL subpath")
} }
s.FakeApp().Srv().Router = s.FakeApp().Srv().RootRouter.PathPrefix(subpath).Subrouter() s.Router = s.RootRouter.PathPrefix(subpath).Subrouter()
pluginsRoute := s.FakeApp().Srv().Router.PathPrefix("/plugins/{plugin_id:[A-Za-z0-9\\_\\-\\.]+}").Subrouter() pluginsRoute := s.Router.PathPrefix("/plugins/{plugin_id:[A-Za-z0-9\\_\\-\\.]+}").Subrouter()
pluginsRoute.HandleFunc("", s.FakeApp().ServePluginRequest) pluginsRoute.HandleFunc("", s.FakeApp().ServePluginRequest)
pluginsRoute.HandleFunc("/public/{public_file:.*}", s.FakeApp().ServePluginPublicRequest) pluginsRoute.HandleFunc("/public/{public_file:.*}", s.FakeApp().ServePluginPublicRequest)
pluginsRoute.HandleFunc("/{anything:.*}", s.FakeApp().ServePluginRequest) pluginsRoute.HandleFunc("/{anything:.*}", s.FakeApp().ServePluginRequest)
// If configured with a subpath, redirect 404s at the root back into the subpath. // If configured with a subpath, redirect 404s at the root back into the subpath.
if subpath != "/" { if subpath != "/" {
s.FakeApp().Srv().RootRouter.NotFoundHandler = http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { s.RootRouter.NotFoundHandler = http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
r.URL.Path = path.Join(subpath, r.URL.Path) r.URL.Path = path.Join(subpath, r.URL.Path)
http.Redirect(w, r, r.URL.String(), http.StatusFound) http.Redirect(w, r, r.URL.String(), http.StatusFound)
}) })
} }
s.FakeApp().Srv().Router.NotFoundHandler = http.HandlerFunc(s.FakeApp().Handle404) s.Router.NotFoundHandler = http.HandlerFunc(s.FakeApp().Handle404)
s.FakeApp().Srv().WebSocketRouter = &WebSocketRouter{ s.WebSocketRouter = &WebSocketRouter{
app: s.FakeApp(), app: s.FakeApp(),
handlers: make(map[string]webSocketHandler), handlers: make(map[string]webSocketHandler),
} }
if err := mailservice.TestConnection(s.FakeApp().Config()); err != nil { if err := mailservice.TestConnection(s.Config()); err != nil {
mlog.Error("Mail server connection test is failed: " + err.Message) mlog.Error("Mail server connection test is failed: " + err.Message)
} }
if _, err := url.ParseRequestURI(*s.FakeApp().Config().ServiceSettings.SiteURL); err != nil { if _, err := url.ParseRequestURI(*s.Config().ServiceSettings.SiteURL); err != nil {
mlog.Error("SiteURL must be set. Some features will operate incorrectly if the SiteURL is not set. See documentation for details: http://about.mattermost.com/default-site-url") mlog.Error("SiteURL must be set. Some features will operate incorrectly if the SiteURL is not set. See documentation for details: http://about.mattermost.com/default-site-url")
} }
backend, appErr := s.FakeApp().FileBackend() backend, appErr := s.FileBackend()
if appErr == nil { if appErr == nil {
appErr = backend.TestConnection() appErr = backend.TestConnection()
} }

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

@@ -61,12 +61,7 @@ func (a *App) NewWebHub() *Hub {
} }
func (a *App) TotalWebsocketConnections() int { func (a *App) TotalWebsocketConnections() int {
count := int64(0) return a.Srv().TotalWebsocketConnections()
for _, hub := range a.Srv().GetHubs() {
count = count + atomic.LoadInt64(&hub.connectionCount)
}
return int(count)
} }
func (a *App) HubStart() { func (a *App) HubStart() {