[MM-61071] Fix errcheck issues in channels/app/admin.go (#28756)

Этот коммит содержится в:
Ben Schumacher
2024-10-31 14:59:32 +01:00
коммит произвёл GitHub
родитель 9fee53fb14
Коммит 2d2c039a27
5 изменённых файлов: 17 добавлений и 27 удалений

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

@@ -85,7 +85,6 @@ issues:
channels/api4/team_test.go|\
channels/api4/user_test.go|\
channels/api4/webhook_test.go|\
channels/app/admin.go|\
channels/app/app_test.go|\
channels/app/authorization_test.go|\
channels/app/auto_responder_test.go|\

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

@@ -70,15 +70,19 @@ func (s *Server) QueryLogs(rctx request.CTX, page, perPage int, logFilter *model
}
}
var appErr *model.AppError
serverNames := logFilter.ServerNames
if len(serverNames) > 0 {
for _, nodeName := range serverNames {
if nodeName == "default" {
AddLocalLogs(rctx, logData, s, page, perPage, nodeName, logFilter)
appErr = AddLocalLogs(rctx, logData, s, page, perPage, nodeName, logFilter)
}
}
} else {
AddLocalLogs(rctx, logData, s, page, perPage, serverName, logFilter)
appErr = AddLocalLogs(rctx, logData, s, page, perPage, serverName, logFilter)
}
if appErr != nil {
return nil, appErr
}
if s.platform.Cluster() != nil && *s.Config().ClusterSettings.Enable {
@@ -237,6 +241,6 @@ func (a *App) GetLatestVersion(rctx request.CTX, latestVersionUrl string) (*mode
return releaseInfoResponse, nil
}
func (a *App) ClearLatestVersionCache(rctx request.CTX) {
latestVersionCache.Remove("latest_version_cache")
func (a *App) clearLatestVersionCache() error {
return latestVersionCache.Remove("latest_version_cache")
}

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

@@ -43,9 +43,10 @@ func TestGetLatestVersion(t *testing.T) {
})
t.Run("get latest mm version from cache", func(t *testing.T) {
th.App.ClearLatestVersionCache(th.Context)
originalResult, err := th.App.GetLatestVersion(th.Context, ts.URL)
require.Nil(t, err)
err := th.App.clearLatestVersionCache()
require.NoError(t, err)
originalResult, appErr := th.App.GetLatestVersion(th.Context, ts.URL)
require.Nil(t, appErr)
// Call same function but mock the GET request to return a different result.
// We are hoping the function will use the cache instead of making the GET request
@@ -68,14 +69,16 @@ func TestGetLatestVersion(t *testing.T) {
}))
defer ts.Close()
cachedResult, err := th.App.GetLatestVersion(th.Context, updatedServer.URL)
require.Nil(t, err)
cachedResult, appErr := th.App.GetLatestVersion(th.Context, updatedServer.URL)
require.Nil(t, appErr)
require.Equal(t, originalResult.TagName, cachedResult.TagName, "did not get cached result")
})
t.Run("get latest mm version error from external", func(t *testing.T) {
th.App.ClearLatestVersionCache(th.Context)
err := th.App.clearLatestVersionCache()
require.NoError(t, err)
errorServer := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusInternalServerError)
_, err := w.Write([]byte(`

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

@@ -494,7 +494,6 @@ type AppIface interface {
CleanUpAfterPostDeletion(c request.CTX, post *model.Post, deleteByID string) *model.AppError
CleanupReportChunks(format string, prefix string, numberOfChunks int) *model.AppError
ClearChannelMembersCache(c request.CTX, channelID string) error
ClearLatestVersionCache(rctx request.CTX)
ClearSessionCacheForAllUsers()
ClearSessionCacheForAllUsersSkipClusterSend()
ClearSessionCacheForUser(userID string)

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

@@ -1521,21 +1521,6 @@ func (a *OpenTracingAppLayer) ClearChannelMembersCache(c request.CTX, channelID
return resultVar0
}
func (a *OpenTracingAppLayer) ClearLatestVersionCache(rctx request.CTX) {
origCtx := a.ctx
span, newCtx := tracing.StartSpanWithParentByContext(a.ctx, "app.ClearLatestVersionCache")
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.ClearLatestVersionCache(rctx)
}
func (a *OpenTracingAppLayer) ClearSessionCacheForAllUsers() {
origCtx := a.ctx
span, newCtx := tracing.StartSpanWithParentByContext(a.ctx, "app.ClearSessionCacheForAllUsers")