From 4ebf9746905c845ee3874f87478d7450391680d8 Mon Sep 17 00:00:00 2001 From: Chris Date: Fri, 2 Mar 2018 10:49:18 -0600 Subject: remove `go Publish(...)` idiom (#8373) --- api/post.go | 5 +---- api/websocket_test.go | 2 +- 2 files changed, 2 insertions(+), 5 deletions(-) (limited to 'api') diff --git a/api/post.go b/api/post.go index 192dc0abc..bed2f3fdb 100644 --- a/api/post.go +++ b/api/post.go @@ -136,10 +136,7 @@ func saveIsPinnedPost(c *Context, w http.ResponseWriter, r *http.Request, isPinn message := model.NewWebSocketEvent(model.WEBSOCKET_EVENT_POST_EDITED, "", rpost.ChannelId, "", nil) message.Add("post", c.App.PostWithProxyAddedToImageURLs(rpost).ToJson()) - - c.App.Go(func() { - c.App.Publish(message) - }) + c.App.Publish(message) c.App.InvalidateCacheForChannelPosts(rpost.ChannelId) diff --git a/api/websocket_test.go b/api/websocket_test.go index 0a39a012f..a3c716abd 100644 --- a/api/websocket_test.go +++ b/api/websocket_test.go @@ -227,7 +227,7 @@ func TestWebSocketEvent(t *testing.T) { } evt2 := model.NewWebSocketEvent(model.WEBSOCKET_EVENT_TYPING, "", "somerandomid", "", nil) - go th.App.Publish(evt2) + th.App.Publish(evt2) time.Sleep(300 * time.Millisecond) eventHit = false -- cgit v1.2.3-1-g7c22 From 4a1802c039a0db2d97e8351c462963a99da857bf Mon Sep 17 00:00:00 2001 From: Joram Wilander Date: Mon, 5 Mar 2018 10:35:26 -0500 Subject: MM-9664 Add invalidation metrics for store caches (#8340) * Add invalidation metrics for store caches * Increment session invalidation metric * Fix tests --- api/channel_test.go | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) (limited to 'api') diff --git a/api/channel_test.go b/api/channel_test.go index 9268d9071..6d9eb5538 100644 --- a/api/channel_test.go +++ b/api/channel_test.go @@ -11,7 +11,6 @@ import ( "github.com/mattermost/mattermost-server/model" "github.com/mattermost/mattermost-server/store" - "github.com/mattermost/mattermost-server/store/sqlstore" ) func TestCreateChannel(t *testing.T) { @@ -374,7 +373,7 @@ func TestUpdateChannel(t *testing.T) { }) th.MakeUserChannelUser(th.BasicUser, channel2) th.MakeUserChannelUser(th.BasicUser, channel3) - sqlstore.ClearChannelCaches() + th.App.Srv.Store.Channel().ClearCaches() if _, err := Client.UpdateChannel(channel2); err == nil { t.Fatal("should have errored not channel admin") @@ -396,7 +395,7 @@ func TestUpdateChannel(t *testing.T) { th.MakeUserChannelAdmin(th.BasicUser, channel2) th.MakeUserChannelAdmin(th.BasicUser, channel3) - sqlstore.ClearChannelCaches() + th.App.Srv.Store.Channel().ClearCaches() if _, err := Client.UpdateChannel(channel2); err != nil { t.Fatal(err) @@ -596,7 +595,7 @@ func TestUpdateChannelHeader(t *testing.T) { }) th.MakeUserChannelUser(th.BasicUser, channel2) th.MakeUserChannelUser(th.BasicUser, channel3) - sqlstore.ClearChannelCaches() + th.App.Srv.Store.Channel().ClearCaches() if _, err := Client.UpdateChannelHeader(data2); err == nil { t.Fatal("should have errored not channel admin") @@ -607,7 +606,7 @@ func TestUpdateChannelHeader(t *testing.T) { th.MakeUserChannelAdmin(th.BasicUser, channel2) th.MakeUserChannelAdmin(th.BasicUser, channel3) - sqlstore.ClearChannelCaches() + th.App.Srv.Store.Channel().ClearCaches() if _, err := Client.UpdateChannelHeader(data2); err != nil { t.Fatal(err) @@ -767,7 +766,7 @@ func TestUpdateChannelPurpose(t *testing.T) { }) th.MakeUserChannelUser(th.BasicUser, channel2) th.MakeUserChannelUser(th.BasicUser, channel3) - sqlstore.ClearChannelCaches() + th.App.Srv.Store.Channel().ClearCaches() if _, err := Client.UpdateChannelPurpose(data2); err == nil { t.Fatal("should have errored not channel admin") @@ -778,7 +777,7 @@ func TestUpdateChannelPurpose(t *testing.T) { th.MakeUserChannelAdmin(th.BasicUser, channel2) th.MakeUserChannelAdmin(th.BasicUser, channel3) - sqlstore.ClearChannelCaches() + th.App.Srv.Store.Channel().ClearCaches() if _, err := Client.UpdateChannelPurpose(data2); err != nil { t.Fatal(err) @@ -1344,7 +1343,7 @@ func TestDeleteChannel(t *testing.T) { th.MakeUserChannelAdmin(th.BasicUser, channel2) th.MakeUserChannelAdmin(th.BasicUser, channel3) - sqlstore.ClearChannelCaches() + th.App.Srv.Store.Channel().ClearCaches() if _, err := Client.DeleteChannel(channel2.Id); err != nil { t.Fatal(err) -- cgit v1.2.3-1-g7c22 From e8943936c51450540a4f2e8e7a2f3a2af90d14db Mon Sep 17 00:00:00 2001 From: Chris Date: Wed, 7 Mar 2018 12:36:40 -0600 Subject: general cleanup (#8387) --- api/context.go | 13 ------------- 1 file changed, 13 deletions(-) (limited to 'api') diff --git a/api/context.go b/api/context.go index a8ff2b694..1eb1e3f4f 100644 --- a/api/context.go +++ b/api/context.go @@ -364,10 +364,6 @@ func NewInvalidParamError(where string, name string) *model.AppError { return err } -func (c *Context) SetUnknownError(where string, details string) { - c.Err = model.NewAppError(where, "api.context.unknown.app_error", nil, details, http.StatusInternalServerError) -} - func (c *Context) SetPermissionError(permission *model.Permission) { c.Err = model.NewAppError("Permissions", "api.context.permissions.app_error", nil, "userId="+c.Session.UserId+", "+"permission="+permission.Id, http.StatusForbidden) } @@ -387,11 +383,6 @@ func (c *Context) SetSiteURLHeader(url string) { c.siteURLHeader = strings.TrimRight(url, "/") } -// TODO see where these are used -func (c *Context) GetTeamURLFromTeam(team *model.Team) string { - return c.GetSiteURLHeader() + "/" + team.Name -} - func (c *Context) GetTeamURL() string { if !c.teamURLValid { c.SetTeamURLFromSession() @@ -406,10 +397,6 @@ func (c *Context) GetSiteURLHeader() string { return c.siteURLHeader } -func (c *Context) GetCurrentTeamMember() *model.TeamMember { - return c.Session.GetTeamByTeamId(c.TeamId) -} - func (c *Context) HandleEtag(etag string, routeName string, w http.ResponseWriter, r *http.Request) bool { metrics := c.App.Metrics if et := r.Header.Get(model.HEADER_ETAG_CLIENT); len(etag) > 0 { -- cgit v1.2.3-1-g7c22 From 4e26594fcb03c378222d2316a004c291d48dd6c7 Mon Sep 17 00:00:00 2001 From: Harrison Healey Date: Mon, 12 Mar 2018 10:21:20 -0400 Subject: Removed mssola/user_agent library (#8417) * Removed mssola/user_agent library * Changed user agent tests to use t.Run --- api/admin.go | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'api') diff --git a/api/admin.go b/api/admin.go index 3b58650cc..6016e48f3 100644 --- a/api/admin.go +++ b/api/admin.go @@ -7,10 +7,10 @@ import ( "net/http" "strconv" + "github.com/avct/uasurfer" "github.com/gorilla/mux" "github.com/mattermost/mattermost-server/app" "github.com/mattermost/mattermost-server/model" - "github.com/mssola/user_agent" ) func (api *API) InitAdmin() { @@ -201,12 +201,11 @@ func downloadComplianceReport(c *Context, w http.ResponseWriter, r *http.Request w.Header().Del("Content-Type") // Content-Type will be set automatically by the http writer // attach extra headers to trigger a download on IE, Edge, and Safari - ua := user_agent.New(r.UserAgent()) - bname, _ := ua.Browser() + ua := uasurfer.Parse(r.UserAgent()) w.Header().Set("Content-Disposition", "attachment;filename=\""+job.JobName()+".zip\"") - if bname == "Edge" || bname == "Internet Explorer" || bname == "Safari" { + if ua.Browser.Name == uasurfer.BrowserIE || ua.Browser.Name == uasurfer.BrowserSafari { // trim off anything before the final / so we just get the file's name w.Header().Set("Content-Type", "application/octet-stream") } -- cgit v1.2.3-1-g7c22