diff --git a/server/channels/api4/file.go b/server/channels/api4/file.go index ee7bb2f680..a070c10193 100644 --- a/server/channels/api4/file.go +++ b/server/channels/api4/file.go @@ -33,14 +33,13 @@ const maxMultipartFormDataBytes = 10 * 1024 // 10Kb func (api *API) InitFile() { api.BaseRoutes.Files.Handle("", api.APISessionRequired(uploadFileStream)).Methods("POST") - api.BaseRoutes.Files.Handle("/search", api.APISessionRequired(searchFilesForUser)).Methods("POST") api.BaseRoutes.File.Handle("", api.APISessionRequiredTrustRequester(getFile)).Methods("GET") api.BaseRoutes.File.Handle("/thumbnail", api.APISessionRequiredTrustRequester(getFileThumbnail)).Methods("GET") api.BaseRoutes.File.Handle("/link", api.APISessionRequired(getFileLink)).Methods("GET") api.BaseRoutes.File.Handle("/preview", api.APISessionRequiredTrustRequester(getFilePreview)).Methods("GET") api.BaseRoutes.File.Handle("/info", api.APISessionRequired(getFileInfo)).Methods("GET") - api.BaseRoutes.Team.Handle("/files/search", api.APISessionRequiredDisableWhenBusy(searchFilesInTeam)).Methods("POST") + api.BaseRoutes.Team.Handle("/files/search", api.APISessionRequiredDisableWhenBusy(searchFiles)).Methods("POST") api.BaseRoutes.PublicFile.Handle("", api.APIHandler(getPublicFile)).Methods("GET") @@ -660,7 +659,7 @@ func getPublicFile(c *Context, w http.ResponseWriter, r *http.Request) { web.WriteFileResponse(info.Name, info.MimeType, info.Size, time.Unix(0, info.UpdateAt*int64(1000*1000)), *c.App.Config().ServiceSettings.WebserverMode, fileReader, false, w, r) } -func searchFilesInTeam(c *Context, w http.ResponseWriter, r *http.Request) { +func searchFiles(c *Context, w http.ResponseWriter, r *http.Request) { c.RequireTeamId() if c.Err != nil { return @@ -671,16 +670,6 @@ func searchFilesInTeam(c *Context, w http.ResponseWriter, r *http.Request) { return } - searchFiles(c, w, r, c.Params.TeamId) -} - -func searchFilesForUser(c *Context, w http.ResponseWriter, r *http.Request) { - if c.App.Config().FeatureFlags.CommandPalette { - searchFiles(c, w, r, "") - } -} - -func searchFiles(c *Context, w http.ResponseWriter, r *http.Request, teamID string) { var params model.SearchParameter jsonErr := json.NewDecoder(r.Body).Decode(¶ms) if jsonErr != nil { @@ -719,18 +708,9 @@ func searchFiles(c *Context, w http.ResponseWriter, r *http.Request, teamID stri includeDeletedChannels = *params.IncludeDeletedChannels } - modifier := "" - if params.Modifier != nil { - modifier = *params.Modifier - } - if modifier != "" && modifier != model.ModifierFiles && modifier != model.ModifierMessages { - c.SetInvalidParam("modifier") - return - } - startTime := time.Now() - results, err := c.App.SearchFilesInTeamForUser(c.AppContext, terms, c.AppContext.Session().UserId, teamID, isOrSearch, includeDeletedChannels, timeZoneOffset, page, perPage, modifier) + results, err := c.App.SearchFilesInTeamForUser(c.AppContext, terms, c.AppContext.Session().UserId, c.Params.TeamId, isOrSearch, includeDeletedChannels, timeZoneOffset, page, perPage) elapsedTime := float64(time.Since(startTime)) / float64(time.Second) metrics := c.App.Metrics() diff --git a/server/channels/api4/post.go b/server/channels/api4/post.go index 8d26d840ef..6e60a82f26 100644 --- a/server/channels/api4/post.go +++ b/server/channels/api4/post.go @@ -773,18 +773,9 @@ func searchPosts(c *Context, w http.ResponseWriter, r *http.Request, teamId stri includeDeletedChannels = *params.IncludeDeletedChannels } - modifier := "" - if params.Modifier != nil { - modifier = *params.Modifier - } - if modifier != "" && modifier != model.ModifierFiles && modifier != model.ModifierMessages { - c.SetInvalidParam("modifier") - return - } - startTime := time.Now() - results, err := c.App.SearchPostsForUser(c.AppContext, terms, c.AppContext.Session().UserId, teamId, isOrSearch, includeDeletedChannels, timeZoneOffset, page, perPage, modifier) + results, err := c.App.SearchPostsForUser(c.AppContext, terms, c.AppContext.Session().UserId, teamId, isOrSearch, includeDeletedChannels, timeZoneOffset, page, perPage) elapsedTime := float64(time.Since(startTime)) / float64(time.Second) metrics := c.App.Metrics() diff --git a/server/channels/api4/user.go b/server/channels/api4/user.go index 558f7e91b0..b3f2a459a3 100644 --- a/server/channels/api4/user.go +++ b/server/channels/api4/user.go @@ -91,7 +91,6 @@ func (api *API) InitUser() { api.BaseRoutes.User.Handle("/uploads", api.APISessionRequired(getUploadsForUser)).Methods("GET") api.BaseRoutes.User.Handle("/channel_members", api.APISessionRequired(getChannelMembersForUser)).Methods("GET") - api.BaseRoutes.User.Handle("/recent_searches", api.APISessionRequiredDisableWhenBusy(getRecentSearches)).Methods("GET") api.BaseRoutes.Users.Handle("/invalid_emails", api.APISessionRequired(getUsersWithInvalidEmails)).Methods("GET") @@ -3397,25 +3396,3 @@ func getUsersWithInvalidEmails(c *Context, w http.ResponseWriter, r *http.Reques c.Logger.Warn("Error writing response", mlog.Err(err)) } } - -func getRecentSearches(c *Context, w http.ResponseWriter, r *http.Request) { - c.RequireUserId() - if c.Err != nil { - return - } - - if !c.App.SessionHasPermissionToUser(*c.AppContext.Session(), c.Params.UserId) { - c.SetPermissionError(model.PermissionEditOtherUsers) - return - } - - searchParams, err := c.App.GetRecentSearchesForUser(c.Params.UserId) - if err != nil { - c.Err = err - return - } - - if err := json.NewEncoder(w).Encode(searchParams); err != nil { - c.Logger.Warn("Error while writing response", mlog.Err(err)) - } -} diff --git a/server/channels/app/app_iface.go b/server/channels/app/app_iface.go index 3ba7d6d3fb..eac41abf0a 100644 --- a/server/channels/app/app_iface.go +++ b/server/channels/app/app_iface.go @@ -751,7 +751,6 @@ type AppIface interface { GetPublicChannelsByIdsForTeam(c request.CTX, teamID string, channelIDs []string) (model.ChannelList, *model.AppError) GetPublicChannelsForTeam(c request.CTX, teamID string, offset int, limit int) (model.ChannelList, *model.AppError) GetReactionsForPost(postID string) ([]*model.Reaction, *model.AppError) - GetRecentSearchesForUser(userID string) ([]*model.SearchParams, *model.AppError) GetRecentlyActiveUsersForTeam(teamID string) (map[string]*model.User, *model.AppError) GetRecentlyActiveUsersForTeamPage(teamID string, page, perPage int, asAdmin bool, viewRestrictions *model.ViewUsersRestrictions) ([]*model.User, *model.AppError) GetRemoteCluster(remoteClusterId string) (*model.RemoteCluster, *model.AppError) @@ -1038,9 +1037,9 @@ type AppIface interface { SearchChannelsUserNotIn(c request.CTX, teamID string, userID string, term string) (model.ChannelList, *model.AppError) SearchEmoji(c request.CTX, name string, prefixOnly bool, limit int) ([]*model.Emoji, *model.AppError) SearchEngine() *searchengine.Broker - SearchFilesInTeamForUser(c *request.Context, terms string, userId string, teamId string, isOrSearch bool, includeDeletedChannels bool, timeZoneOffset int, page, perPage int, modifier string) (*model.FileInfoList, *model.AppError) + SearchFilesInTeamForUser(c *request.Context, terms string, userId string, teamId string, isOrSearch bool, includeDeletedChannels bool, timeZoneOffset int, page, perPage int) (*model.FileInfoList, *model.AppError) SearchGroupChannels(c request.CTX, userID, term string) (model.ChannelList, *model.AppError) - SearchPostsForUser(c *request.Context, terms string, userID string, teamID string, isOrSearch bool, includeDeletedChannels bool, timeZoneOffset int, page, perPage int, modifier string) (*model.PostSearchResults, *model.AppError) + SearchPostsForUser(c *request.Context, terms string, userID string, teamID string, isOrSearch bool, includeDeletedChannels bool, timeZoneOffset int, page, perPage int) (*model.PostSearchResults, *model.AppError) SearchPostsInTeam(teamID string, paramsList []*model.SearchParams) (*model.PostList, *model.AppError) SearchPrivateTeams(searchOpts *model.TeamSearch) ([]*model.Team, *model.AppError) SearchPublicTeams(searchOpts *model.TeamSearch) ([]*model.Team, *model.AppError) diff --git a/server/channels/app/file.go b/server/channels/app/file.go index bc77ed9a65..3a37b8b1e7 100644 --- a/server/channels/app/file.go +++ b/server/channels/app/file.go @@ -1363,7 +1363,7 @@ func populateZipfile(w *zip.Writer, fileDatas []model.FileData) error { return nil } -func (a *App) SearchFilesInTeamForUser(c *request.Context, terms string, userId string, teamId string, isOrSearch bool, includeDeletedChannels bool, timeZoneOffset int, page, perPage int, modifier string) (*model.FileInfoList, *model.AppError) { +func (a *App) SearchFilesInTeamForUser(c *request.Context, terms string, userId string, teamId string, isOrSearch bool, includeDeletedChannels bool, timeZoneOffset int, page, perPage int) (*model.FileInfoList, *model.AppError) { paramsList := model.ParseSearchParams(strings.TrimSpace(terms), timeZoneOffset) includeDeleted := includeDeletedChannels && *a.Config().TeamSettings.ExperimentalViewArchivedChannels @@ -1374,7 +1374,6 @@ func (a *App) SearchFilesInTeamForUser(c *request.Context, terms string, userId finalParamsList := []*model.SearchParams{} for _, params := range paramsList { - params.Modifier = modifier params.OrTerms = isOrSearch params.IncludeDeletedChannels = includeDeleted // Don't allow users to search for "*" diff --git a/server/channels/app/file_test.go b/server/channels/app/file_test.go index 85bad0eb73..06977c11f1 100644 --- a/server/channels/app/file_test.go +++ b/server/channels/app/file_test.go @@ -403,7 +403,7 @@ func TestSearchFilesInTeamForUser(t *testing.T) { page := 0 - results, err := th.App.SearchFilesInTeamForUser(th.Context, searchTerm, th.BasicUser.Id, th.BasicTeam.Id, false, false, 0, page, perPage, model.ModifierFiles) + results, err := th.App.SearchFilesInTeamForUser(th.Context, searchTerm, th.BasicUser.Id, th.BasicTeam.Id, false, false, 0, page, perPage) require.Nil(t, err) require.NotNil(t, results) @@ -424,7 +424,7 @@ func TestSearchFilesInTeamForUser(t *testing.T) { page := 1 - results, err := th.App.SearchFilesInTeamForUser(th.Context, searchTerm, th.BasicUser.Id, th.BasicTeam.Id, false, false, 0, page, perPage, model.ModifierFiles) + results, err := th.App.SearchFilesInTeamForUser(th.Context, searchTerm, th.BasicUser.Id, th.BasicTeam.Id, false, false, 0, page, perPage) require.Nil(t, err) require.NotNil(t, results) @@ -454,7 +454,7 @@ func TestSearchFilesInTeamForUser(t *testing.T) { th.App.Srv().Platform().SearchEngine.ElasticsearchEngine = nil }() - results, err := th.App.SearchFilesInTeamForUser(th.Context, searchTerm, th.BasicUser.Id, th.BasicTeam.Id, false, false, 0, page, perPage, model.ModifierFiles) + results, err := th.App.SearchFilesInTeamForUser(th.Context, searchTerm, th.BasicUser.Id, th.BasicTeam.Id, false, false, 0, page, perPage) require.Nil(t, err) require.NotNil(t, results) @@ -482,7 +482,7 @@ func TestSearchFilesInTeamForUser(t *testing.T) { th.App.Srv().Platform().SearchEngine.ElasticsearchEngine = nil }() - results, err := th.App.SearchFilesInTeamForUser(th.Context, searchTerm, th.BasicUser.Id, th.BasicTeam.Id, false, false, 0, page, perPage, model.ModifierFiles) + results, err := th.App.SearchFilesInTeamForUser(th.Context, searchTerm, th.BasicUser.Id, th.BasicTeam.Id, false, false, 0, page, perPage) require.Nil(t, err) require.NotNil(t, results) @@ -507,7 +507,7 @@ func TestSearchFilesInTeamForUser(t *testing.T) { th.App.Srv().Platform().SearchEngine.ElasticsearchEngine = nil }() - results, err := th.App.SearchFilesInTeamForUser(th.Context, searchTerm, th.BasicUser.Id, th.BasicTeam.Id, false, false, 0, page, perPage, model.ModifierFiles) + results, err := th.App.SearchFilesInTeamForUser(th.Context, searchTerm, th.BasicUser.Id, th.BasicTeam.Id, false, false, 0, page, perPage) require.Nil(t, err) require.NotNil(t, results) @@ -540,7 +540,7 @@ func TestSearchFilesInTeamForUser(t *testing.T) { th.App.Srv().Platform().SearchEngine.ElasticsearchEngine = nil }() - results, err := th.App.SearchFilesInTeamForUser(th.Context, searchTerm, th.BasicUser.Id, th.BasicTeam.Id, false, false, 0, page, perPage, model.ModifierFiles) + results, err := th.App.SearchFilesInTeamForUser(th.Context, searchTerm, th.BasicUser.Id, th.BasicTeam.Id, false, false, 0, page, perPage) require.Nil(t, err) assert.Equal(t, []string{}, results.Order) diff --git a/server/channels/app/opentracing/opentracing_layer.go b/server/channels/app/opentracing/opentracing_layer.go index 274aa206e6..473381a73b 100644 --- a/server/channels/app/opentracing/opentracing_layer.go +++ b/server/channels/app/opentracing/opentracing_layer.go @@ -8720,28 +8720,6 @@ func (a *OpenTracingAppLayer) GetReactionsForPost(postID string) ([]*model.React return resultVar0, resultVar1 } -func (a *OpenTracingAppLayer) GetRecentSearchesForUser(userID string) ([]*model.SearchParams, *model.AppError) { - origCtx := a.ctx - span, newCtx := tracing.StartSpanWithParentByContext(a.ctx, "app.GetRecentSearchesForUser") - - a.ctx = newCtx - a.app.Srv().Store().SetContext(newCtx) - defer func() { - a.app.Srv().Store().SetContext(origCtx) - a.ctx = origCtx - }() - - defer span.Finish() - resultVar0, resultVar1 := a.app.GetRecentSearchesForUser(userID) - - if resultVar1 != nil { - span.LogFields(spanlog.Error(resultVar1)) - ext.Error.Set(span, true) - } - - return resultVar0, resultVar1 -} - func (a *OpenTracingAppLayer) GetRecentlyActiveUsersForTeam(teamID string) (map[string]*model.User, *model.AppError) { origCtx := a.ctx span, newCtx := tracing.StartSpanWithParentByContext(a.ctx, "app.GetRecentlyActiveUsersForTeam") @@ -15337,7 +15315,7 @@ func (a *OpenTracingAppLayer) SearchEngine() *searchengine.Broker { return resultVar0 } -func (a *OpenTracingAppLayer) SearchFilesInTeamForUser(c *request.Context, terms string, userId string, teamId string, isOrSearch bool, includeDeletedChannels bool, timeZoneOffset int, page int, perPage int, modifier string) (*model.FileInfoList, *model.AppError) { +func (a *OpenTracingAppLayer) SearchFilesInTeamForUser(c *request.Context, terms string, userId string, teamId string, isOrSearch bool, includeDeletedChannels bool, timeZoneOffset int, page int, perPage int) (*model.FileInfoList, *model.AppError) { origCtx := a.ctx span, newCtx := tracing.StartSpanWithParentByContext(a.ctx, "app.SearchFilesInTeamForUser") @@ -15349,7 +15327,7 @@ func (a *OpenTracingAppLayer) SearchFilesInTeamForUser(c *request.Context, terms }() defer span.Finish() - resultVar0, resultVar1 := a.app.SearchFilesInTeamForUser(c, terms, userId, teamId, isOrSearch, includeDeletedChannels, timeZoneOffset, page, perPage, modifier) + resultVar0, resultVar1 := a.app.SearchFilesInTeamForUser(c, terms, userId, teamId, isOrSearch, includeDeletedChannels, timeZoneOffset, page, perPage) if resultVar1 != nil { span.LogFields(spanlog.Error(resultVar1)) @@ -15381,7 +15359,7 @@ func (a *OpenTracingAppLayer) SearchGroupChannels(c request.CTX, userID string, return resultVar0, resultVar1 } -func (a *OpenTracingAppLayer) SearchPostsForUser(c *request.Context, terms string, userID string, teamID string, isOrSearch bool, includeDeletedChannels bool, timeZoneOffset int, page int, perPage int, modifier string) (*model.PostSearchResults, *model.AppError) { +func (a *OpenTracingAppLayer) SearchPostsForUser(c *request.Context, terms string, userID string, teamID string, isOrSearch bool, includeDeletedChannels bool, timeZoneOffset int, page int, perPage int) (*model.PostSearchResults, *model.AppError) { origCtx := a.ctx span, newCtx := tracing.StartSpanWithParentByContext(a.ctx, "app.SearchPostsForUser") @@ -15393,7 +15371,7 @@ func (a *OpenTracingAppLayer) SearchPostsForUser(c *request.Context, terms strin }() defer span.Finish() - resultVar0, resultVar1 := a.app.SearchPostsForUser(c, terms, userID, teamID, isOrSearch, includeDeletedChannels, timeZoneOffset, page, perPage, modifier) + resultVar0, resultVar1 := a.app.SearchPostsForUser(c, terms, userID, teamID, isOrSearch, includeDeletedChannels, timeZoneOffset, page, perPage) if resultVar1 != nil { span.LogFields(spanlog.Error(resultVar1)) diff --git a/server/channels/app/plugin_api.go b/server/channels/app/plugin_api.go index df554070e8..9f37368356 100644 --- a/server/channels/app/plugin_api.go +++ b/server/channels/app/plugin_api.go @@ -546,7 +546,7 @@ func (api *PluginAPI) SearchPostsInTeamForUser(teamID string, userID string, sea includeDeletedChannels = *searchParams.IncludeDeletedChannels } - results, appErr := api.app.SearchPostsForUser(api.ctx, terms, userID, teamID, isOrSearch, includeDeletedChannels, timeZoneOffset, page, perPage, model.ModifierMessages) + results, appErr := api.app.SearchPostsForUser(api.ctx, terms, userID, teamID, isOrSearch, includeDeletedChannels, timeZoneOffset, page, perPage) if results != nil { results = results.ForPlugin() } diff --git a/server/channels/app/post.go b/server/channels/app/post.go index b48f9631e7..ed897fdc9b 100644 --- a/server/channels/app/post.go +++ b/server/channels/app/post.go @@ -1580,7 +1580,7 @@ func (a *App) SearchPostsInTeam(teamID string, paramsList []*model.SearchParams) }) } -func (a *App) SearchPostsForUser(c *request.Context, terms string, userID string, teamID string, isOrSearch bool, includeDeletedChannels bool, timeZoneOffset int, page, perPage int, modifier string) (*model.PostSearchResults, *model.AppError) { +func (a *App) SearchPostsForUser(c *request.Context, terms string, userID string, teamID string, isOrSearch bool, includeDeletedChannels bool, timeZoneOffset int, page, perPage int) (*model.PostSearchResults, *model.AppError) { var postSearchResults *model.PostSearchResults paramsList := model.ParseSearchParams(strings.TrimSpace(terms), timeZoneOffset) includeDeleted := includeDeletedChannels && *a.Config().TeamSettings.ExperimentalViewArchivedChannels @@ -1592,7 +1592,6 @@ func (a *App) SearchPostsForUser(c *request.Context, terms string, userID string finalParamsList := []*model.SearchParams{} for _, params := range paramsList { - params.Modifier = modifier params.OrTerms = isOrSearch params.IncludeDeletedChannels = includeDeleted // Don't allow users to search for "*" @@ -1635,15 +1634,6 @@ func (a *App) SearchPostsForUser(c *request.Context, terms string, userID string return postSearchResults, nil } -func (a *App) GetRecentSearchesForUser(userID string) ([]*model.SearchParams, *model.AppError) { - searchParams, err := a.Srv().Store().Post().GetRecentSearchesForUser(userID) - if err != nil { - return nil, model.NewAppError("GetRecentSearchesForUser", "app.recent_searches.app_error", nil, "", http.StatusInternalServerError).Wrap(err) - } - - return searchParams, nil -} - func (a *App) GetFileInfosForPostWithMigration(postID string, includeDeleted bool) ([]*model.FileInfo, *model.AppError) { pchan := make(chan store.StoreResult, 1) diff --git a/server/channels/app/post_test.go b/server/channels/app/post_test.go index 26d900287c..f93978cf89 100644 --- a/server/channels/app/post_test.go +++ b/server/channels/app/post_test.go @@ -1429,7 +1429,7 @@ func TestSearchPostsForUser(t *testing.T) { page := 0 - results, err := th.App.SearchPostsForUser(th.Context, searchTerm, th.BasicUser.Id, th.BasicTeam.Id, false, false, 0, page, perPage, model.ModifierMessages) + results, err := th.App.SearchPostsForUser(th.Context, searchTerm, th.BasicUser.Id, th.BasicTeam.Id, false, false, 0, page, perPage) assert.Nil(t, err) assert.Equal(t, []string{ @@ -1449,7 +1449,7 @@ func TestSearchPostsForUser(t *testing.T) { page := 1 - results, err := th.App.SearchPostsForUser(th.Context, searchTerm, th.BasicUser.Id, th.BasicTeam.Id, false, false, 0, page, perPage, model.ModifierMessages) + results, err := th.App.SearchPostsForUser(th.Context, searchTerm, th.BasicUser.Id, th.BasicTeam.Id, false, false, 0, page, perPage) assert.Nil(t, err) assert.Equal(t, []string{}, results.Order) @@ -1478,7 +1478,7 @@ func TestSearchPostsForUser(t *testing.T) { th.App.Srv().Platform().SearchEngine.ElasticsearchEngine = nil }() - results, err := th.App.SearchPostsForUser(th.Context, searchTerm, th.BasicUser.Id, th.BasicTeam.Id, false, false, 0, page, perPage, model.ModifierMessages) + results, err := th.App.SearchPostsForUser(th.Context, searchTerm, th.BasicUser.Id, th.BasicTeam.Id, false, false, 0, page, perPage) assert.Nil(t, err) assert.Equal(t, resultsPage, results.Order) @@ -1505,7 +1505,7 @@ func TestSearchPostsForUser(t *testing.T) { th.App.Srv().Platform().SearchEngine.ElasticsearchEngine = nil }() - results, err := th.App.SearchPostsForUser(th.Context, searchTerm, th.BasicUser.Id, th.BasicTeam.Id, false, false, 0, page, perPage, model.ModifierMessages) + results, err := th.App.SearchPostsForUser(th.Context, searchTerm, th.BasicUser.Id, th.BasicTeam.Id, false, false, 0, page, perPage) assert.Nil(t, err) assert.Equal(t, resultsPage, results.Order) @@ -1529,7 +1529,7 @@ func TestSearchPostsForUser(t *testing.T) { th.App.Srv().Platform().SearchEngine.ElasticsearchEngine = nil }() - results, err := th.App.SearchPostsForUser(th.Context, searchTerm, th.BasicUser.Id, th.BasicTeam.Id, false, false, 0, page, perPage, model.ModifierMessages) + results, err := th.App.SearchPostsForUser(th.Context, searchTerm, th.BasicUser.Id, th.BasicTeam.Id, false, false, 0, page, perPage) assert.Nil(t, err) assert.Equal(t, []string{ @@ -1561,7 +1561,7 @@ func TestSearchPostsForUser(t *testing.T) { th.App.Srv().Platform().SearchEngine.ElasticsearchEngine = nil }() - results, err := th.App.SearchPostsForUser(th.Context, searchTerm, th.BasicUser.Id, th.BasicTeam.Id, false, false, 0, page, perPage, model.ModifierMessages) + results, err := th.App.SearchPostsForUser(th.Context, searchTerm, th.BasicUser.Id, th.BasicTeam.Id, false, false, 0, page, perPage) assert.Nil(t, err) assert.Equal(t, []string{}, results.Order) diff --git a/server/channels/db/migrations/mysql/000084_recent_searches.down.sql b/server/channels/db/migrations/mysql/000084_recent_searches.down.sql index c2e20271c6..270536b5dd 100644 --- a/server/channels/db/migrations/mysql/000084_recent_searches.down.sql +++ b/server/channels/db/migrations/mysql/000084_recent_searches.down.sql @@ -1 +1,2 @@ -DROP TABLE IF EXISTS RecentSearches; \ No newline at end of file +-- This table is unused, and will be dropped in a future ESR. +DROP TABLE IF EXISTS RecentSearches; diff --git a/server/channels/db/migrations/mysql/000084_recent_searches.up.sql b/server/channels/db/migrations/mysql/000084_recent_searches.up.sql index 33986fa149..34c70d4f0a 100644 --- a/server/channels/db/migrations/mysql/000084_recent_searches.up.sql +++ b/server/channels/db/migrations/mysql/000084_recent_searches.up.sql @@ -1,7 +1,8 @@ +-- This table is unused, and will be dropped in a future ESR. CREATE TABLE IF NOT EXISTS RecentSearches ( UserId CHAR(26), SearchPointer int, Query json, CreateAt bigint NOT NULL, PRIMARY KEY (UserId, SearchPointer) -); \ No newline at end of file +); diff --git a/server/channels/db/migrations/postgres/000084_recent_searches.down.sql b/server/channels/db/migrations/postgres/000084_recent_searches.down.sql index 30d2c222e9..43dac62a80 100644 --- a/server/channels/db/migrations/postgres/000084_recent_searches.down.sql +++ b/server/channels/db/migrations/postgres/000084_recent_searches.down.sql @@ -1 +1,2 @@ -DROP TABLE IF EXISTS recentsearches; \ No newline at end of file +-- This table is unused, and will be dropped in a future ESR. +DROP TABLE IF EXISTS recentsearches; diff --git a/server/channels/db/migrations/postgres/000084_recent_searches.up.sql b/server/channels/db/migrations/postgres/000084_recent_searches.up.sql index 5e9930753a..8d686339aa 100644 --- a/server/channels/db/migrations/postgres/000084_recent_searches.up.sql +++ b/server/channels/db/migrations/postgres/000084_recent_searches.up.sql @@ -1,7 +1,8 @@ +-- This table is unused, and will be dropped in a future ESR. CREATE TABLE IF NOT EXISTS recentsearches ( userid CHAR(26), searchpointer int, query jsonb, createat bigint NOT NULL, PRIMARY KEY (userid, searchpointer) -); \ No newline at end of file +); diff --git a/server/channels/store/opentracinglayer/opentracinglayer.go b/server/channels/store/opentracinglayer/opentracinglayer.go index 919e5bf6d4..e91e0353f6 100644 --- a/server/channels/store/opentracinglayer/opentracinglayer.go +++ b/server/channels/store/opentracinglayer/opentracinglayer.go @@ -6422,24 +6422,6 @@ func (s *OpenTracingLayerPostStore) GetPostsSinceForSync(options model.GetPostsS return result, resultVar1, err } -func (s *OpenTracingLayerPostStore) GetRecentSearchesForUser(userID string) ([]*model.SearchParams, error) { - origCtx := s.Root.Store.Context() - span, newCtx := tracing.StartSpanWithParentByContext(s.Root.Store.Context(), "PostStore.GetRecentSearchesForUser") - s.Root.Store.SetContext(newCtx) - defer func() { - s.Root.Store.SetContext(origCtx) - }() - - defer span.Finish() - result, err := s.PostStore.GetRecentSearchesForUser(userID) - if err != nil { - span.LogFields(spanlog.Error(err)) - ext.Error.Set(span, true) - } - - return result, err -} - func (s *OpenTracingLayerPostStore) GetRepliesForExport(parentID string) ([]*model.ReplyForExport, error) { origCtx := s.Root.Store.Context() span, newCtx := tracing.StartSpanWithParentByContext(s.Root.Store.Context(), "PostStore.GetRepliesForExport") @@ -6525,24 +6507,6 @@ func (s *OpenTracingLayerPostStore) InvalidateLastPostTimeCache(channelID string } -func (s *OpenTracingLayerPostStore) LogRecentSearch(userID string, searchQuery []byte, createAt int64) error { - origCtx := s.Root.Store.Context() - span, newCtx := tracing.StartSpanWithParentByContext(s.Root.Store.Context(), "PostStore.LogRecentSearch") - s.Root.Store.SetContext(newCtx) - defer func() { - s.Root.Store.SetContext(origCtx) - }() - - defer span.Finish() - err := s.PostStore.LogRecentSearch(userID, searchQuery, createAt) - if err != nil { - span.LogFields(spanlog.Error(err)) - ext.Error.Set(span, true) - } - - return err -} - func (s *OpenTracingLayerPostStore) Overwrite(post *model.Post) (*model.Post, error) { origCtx := s.Root.Store.Context() span, newCtx := tracing.StartSpanWithParentByContext(s.Root.Store.Context(), "PostStore.Overwrite") diff --git a/server/channels/store/retrylayer/retrylayer.go b/server/channels/store/retrylayer/retrylayer.go index 0fc64a7833..f5a8c5c539 100644 --- a/server/channels/store/retrylayer/retrylayer.go +++ b/server/channels/store/retrylayer/retrylayer.go @@ -7271,27 +7271,6 @@ func (s *RetryLayerPostStore) GetPostsSinceForSync(options model.GetPostsSinceFo } -func (s *RetryLayerPostStore) GetRecentSearchesForUser(userID string) ([]*model.SearchParams, error) { - - tries := 0 - for { - result, err := s.PostStore.GetRecentSearchesForUser(userID) - if err == nil { - return result, nil - } - if !isRepeatableError(err) { - return result, err - } - tries++ - if tries >= 3 { - err = errors.Wrap(err, "giving up after 3 consecutive repeatable transaction failures") - return result, err - } - timepkg.Sleep(100 * timepkg.Millisecond) - } - -} - func (s *RetryLayerPostStore) GetRepliesForExport(parentID string) ([]*model.ReplyForExport, error) { tries := 0 @@ -7382,27 +7361,6 @@ func (s *RetryLayerPostStore) InvalidateLastPostTimeCache(channelID string) { } -func (s *RetryLayerPostStore) LogRecentSearch(userID string, searchQuery []byte, createAt int64) error { - - tries := 0 - for { - err := s.PostStore.LogRecentSearch(userID, searchQuery, createAt) - if err == nil { - return nil - } - if !isRepeatableError(err) { - return err - } - tries++ - if tries >= 3 { - err = errors.Wrap(err, "giving up after 3 consecutive repeatable transaction failures") - return err - } - timepkg.Sleep(100 * timepkg.Millisecond) - } - -} - func (s *RetryLayerPostStore) Overwrite(post *model.Post) (*model.Post, error) { tries := 0 diff --git a/server/channels/store/sqlstore/channel_store.go b/server/channels/store/sqlstore/channel_store.go index 084e77ed93..a6db92f595 100644 --- a/server/channels/store/sqlstore/channel_store.go +++ b/server/channels/store/sqlstore/channel_store.go @@ -1543,16 +1543,14 @@ func (s SqlChannelStore) getByName(teamId string, name string, includeDeleted bo query := s.getQueryBuilder(). Select("*"). From("Channels"). - Where(sq.Eq{"Name": name}) - - if !includeDeleted { - query = query.Where(sq.Eq{"DeleteAt": 0}) - } - if teamId != "" { - query = query.Where(sq.Or{ + Where(sq.Eq{"Name": name}). + Where(sq.Or{ sq.Eq{"TeamId": teamId}, sq.Eq{"TeamId": ""}, }) + + if !includeDeleted { + query = query.Where(sq.Eq{"DeleteAt": 0}) } channel := model.Channel{} diff --git a/server/channels/store/sqlstore/file_info_store.go b/server/channels/store/sqlstore/file_info_store.go index 801e235a85..6c67ad3cd2 100644 --- a/server/channels/store/sqlstore/file_info_store.go +++ b/server/channels/store/sqlstore/file_info_store.go @@ -5,7 +5,6 @@ package sqlstore import ( "database/sql" - "encoding/json" "fmt" "regexp" "strconv" @@ -512,33 +511,12 @@ func (fs SqlFileInfoStore) Search(paramsList []*model.SearchParams, userId, team From("FileInfo"). LeftJoin("Channels as C ON C.Id=FileInfo.ChannelId"). LeftJoin("ChannelMembers as CM ON C.Id=CM.ChannelId"). + Where(sq.Or{sq.Eq{"C.TeamId": teamId}, sq.Eq{"C.TeamId": ""}}). Where(sq.Eq{"FileInfo.DeleteAt": 0}). OrderBy("FileInfo.CreateAt DESC"). Limit(100) - if teamId != "" { - query = query.Where(sq.Or{ - sq.Eq{"C.TeamId": teamId}, - sq.Eq{"C.TeamId": ""}, - }) - } - - now := model.GetMillis() for _, params := range paramsList { - if params.Modifier == model.ModifierFiles { - // Deliberately keeping non-alphanumeric characters to - // prevent surprises in UI. - buf, err := json.Marshal(params) - if err != nil { - return nil, err - } - - err = fs.stores.post.LogRecentSearch(userId, buf, now) - if err != nil { - return nil, err - } - } - params.Terms = removeNonAlphaNumericUnquotedTerms(params.Terms, " ") if !params.IncludeDeletedChannels { diff --git a/server/channels/store/sqlstore/post_store.go b/server/channels/store/sqlstore/post_store.go index c470ba8a8d..62322f7dad 100644 --- a/server/channels/store/sqlstore/post_store.go +++ b/server/channels/store/sqlstore/post_store.go @@ -6,11 +6,9 @@ package sqlstore import ( "context" "database/sql" - "encoding/json" "fmt" "reflect" "regexp" - "strconv" "strings" "sync" @@ -1923,13 +1921,11 @@ func (s *SqlPostStore) buildSearchPostFilterClause(teamID string, fromUsers []st } // Sub-query builder. - sb := s.getSubQueryBuilder(). - Select("Id"). - From("Users, TeamMembers"). - Where(sq.Expr("Users.Id = TeamMembers.UserId")) - if teamID != "" { - sb = sb.Where(sq.Eq{"TeamMembers.TeamId": teamID}) - } + sb := s.getSubQueryBuilder().Select("Id").From("Users, TeamMembers").Where( + sq.And{ + sq.Eq{"TeamMembers.TeamId": teamID}, + sq.Expr("Users.Id = TeamMembers.UserId"), + }) sb = s.buildSearchUserFilterClause(fromUsers, false, userByUsername, sb) sb = s.buildSearchUserFilterClause(excludedUsers, true, userByUsername, sb) subQuery, subQueryArgs, err := sb.ToSql() @@ -2710,7 +2706,7 @@ func (s *SqlPostStore) GetDirectPostParentsForExportAfter(limit int, afterId str } //nolint:unparam -func (s *SqlPostStore) SearchPostsForUser(paramsList []*model.SearchParams, userID, teamId string, page, perPage int) (*model.PostSearchResults, error) { +func (s *SqlPostStore) SearchPostsForUser(paramsList []*model.SearchParams, userId, teamId string, page, perPage int) (*model.PostSearchResults, error) { // Since we don't support paging for DB search, we just return nothing for later pages if page > 0 { return model.MakePostSearchResults(model.NewPostList(), nil), nil @@ -2720,22 +2716,11 @@ func (s *SqlPostStore) SearchPostsForUser(paramsList []*model.SearchParams, user return nil, err } - now := model.GetMillis() + var wg sync.WaitGroup + pchan := make(chan store.StoreResult, len(paramsList)) - var wg sync.WaitGroup for _, params := range paramsList { - // Deliberately keeping non-alphanumeric characters to - // prevent surprises in UI. - buf, err := json.Marshal(params) - if err != nil { - return nil, err - } - err = s.LogRecentSearch(userID, buf, now) - if err != nil { - return nil, err - } - // remove any unquoted term that contains only non-alphanumeric chars // ex: abcd "**" && abc >> abcd "**" abc params.Terms = removeNonAlphaNumericUnquotedTerms(params.Terms, " ") @@ -2744,7 +2729,7 @@ func (s *SqlPostStore) SearchPostsForUser(paramsList []*model.SearchParams, user go func(params *model.SearchParams) { defer wg.Done() - postList, err := s.search(teamId, userID, params, false, false) + postList, err := s.search(teamId, userId, params, false, false) pchan <- store.StoreResult{Data: postList, NErr: err} }(params) } @@ -2767,103 +2752,6 @@ func (s *SqlPostStore) SearchPostsForUser(paramsList []*model.SearchParams, user return model.MakePostSearchResults(posts, nil), nil } -const lastSearchesLimit = 5 - -func (s *SqlPostStore) LogRecentSearch(userID string, searchQuery []byte, createAt int64) (err error) { - transaction, err := s.GetMasterX().Beginx() - if err != nil { - return errors.Wrap(err, "begin_transaction") - } - - defer finalizeTransactionX(transaction, &err) - - var lastSearchPointer int - var queryStr string - // get search_pointer - // We coalesce to -1 because we want to start from 0 - if s.DriverName() == model.DatabaseDriverPostgres { - queryStr = `SELECT COALESCE((props->>'last_search_pointer')::integer, -1) - FROM Users - WHERE Id=?` - } else { - queryStr = `SELECT COALESCE(CAST(JSON_EXTRACT(Props, '$.last_search_pointer') as unsigned), -1) - FROM Users - WHERE Id=?` - } - err = transaction.Get(&lastSearchPointer, queryStr, userID) - if err != nil { - return errors.Wrapf(err, "failed to find last_search_pointer for user=%s", userID) - } - - // (ptr+1)%lastSearchesLimit - lastSearchPointer = (lastSearchPointer + 1) % lastSearchesLimit - - if s.IsBinaryParamEnabled() { - searchQuery = AppendBinaryFlag(searchQuery) - } - - // insert at pointer - query := s.getQueryBuilder(). - Insert("RecentSearches"). - Columns("UserId", "SearchPointer", "Query", "CreateAt"). - Values(userID, lastSearchPointer, searchQuery, createAt) - - if s.DriverName() == model.DatabaseDriverPostgres { - query = query.SuffixExpr(sq.Expr("ON CONFLICT (userid, searchpointer) DO UPDATE SET Query = ?, CreateAt = ?", searchQuery, createAt)) - } else { - query = query.SuffixExpr(sq.Expr("ON DUPLICATE KEY UPDATE Query = ?, CreateAt = ?", searchQuery, createAt)) - } - - queryString, args, err := query.ToSql() - if err != nil { - return errors.Wrap(err, "log_recent_search_tosql") - } - - if _, err2 := transaction.Exec(queryString, args...); err2 != nil { - return errors.Wrapf(err2, "failed to upsert recent_search for user=%s", userID) - } - - // write ptr on users prop - if s.DriverName() == model.DatabaseDriverPostgres { - _, err = transaction.Exec(`UPDATE Users - SET Props = jsonb_set(Props, $1, $2) - WHERE Id = $3`, jsonKeyPath("last_search_pointer"), jsonStringVal(strconv.Itoa(lastSearchPointer)), userID) - } else { - _, err = transaction.Exec(`UPDATE Users - SET Props = JSON_SET(Props, ?, ?) - WHERE Id = ?`, "$.last_search_pointer", strconv.Itoa(lastSearchPointer), userID) - } - if err != nil { - return errors.Wrapf(err, "failed to update last_search_pointer for user=%s", userID) - } - - if err2 := transaction.Commit(); err2 != nil { - return errors.Wrap(err2, "commit_transaction") - } - - return nil -} - -func (s *SqlPostStore) GetRecentSearchesForUser(userID string) ([]*model.SearchParams, error) { - params := [][]byte{} - err := s.GetReplicaX().Select(¶ms, `SELECT query - FROM RecentSearches - WHERE UserId=? - ORDER BY CreateAt DESC`, userID) - if err != nil { - return nil, errors.Wrapf(err, "failed to get recent searches for user=%s", userID) - } - - res := make([]*model.SearchParams, len(params)) - for i, param := range params { - err = json.Unmarshal(param, &res[i]) - if err != nil { - return nil, errors.Wrapf(err, "failed to unmarshal recent search query for user=%s", userID) - } - } - return res, nil -} - func (s *SqlPostStore) GetOldestEntityCreationTime() (int64, error) { query := s.getQueryBuilder().Select("MIN(min_createat) min_createat"). Suffix(`FROM ( diff --git a/server/channels/store/store.go b/server/channels/store/store.go index d4c0d4d006..47492889f9 100644 --- a/server/channels/store/store.go +++ b/server/channels/store/store.go @@ -396,8 +396,6 @@ type PostStore interface { GetRepliesForExport(parentID string) ([]*model.ReplyForExport, error) GetDirectPostParentsForExportAfter(limit int, afterID string) ([]*model.DirectPostForExport, error) SearchPostsForUser(paramsList []*model.SearchParams, userID, teamID string, page, perPage int) (*model.PostSearchResults, error) - GetRecentSearchesForUser(userID string) ([]*model.SearchParams, error) - LogRecentSearch(userID string, searchQuery []byte, createAt int64) error GetOldestEntityCreationTime() (int64, error) HasAutoResponsePostByUserSince(options model.GetPostsSinceOptions, userId string) (bool, error) GetPostsSinceForSync(options model.GetPostsSinceForSyncOptions, cursor model.GetPostsSinceForSyncCursor, limit int) ([]*model.Post, model.GetPostsSinceForSyncCursor, error) diff --git a/server/channels/store/storetest/mocks/PostStore.go b/server/channels/store/storetest/mocks/PostStore.go index 336c9eb6fa..880b12882b 100644 --- a/server/channels/store/storetest/mocks/PostStore.go +++ b/server/channels/store/storetest/mocks/PostStore.go @@ -788,32 +788,6 @@ func (_m *PostStore) GetPostsSinceForSync(options model.GetPostsSinceForSyncOpti return r0, r1, r2 } -// GetRecentSearchesForUser provides a mock function with given fields: userID -func (_m *PostStore) GetRecentSearchesForUser(userID string) ([]*model.SearchParams, error) { - ret := _m.Called(userID) - - var r0 []*model.SearchParams - var r1 error - if rf, ok := ret.Get(0).(func(string) ([]*model.SearchParams, error)); ok { - return rf(userID) - } - if rf, ok := ret.Get(0).(func(string) []*model.SearchParams); ok { - r0 = rf(userID) - } else { - if ret.Get(0) != nil { - r0 = ret.Get(0).([]*model.SearchParams) - } - } - - if rf, ok := ret.Get(1).(func(string) error); ok { - r1 = rf(userID) - } else { - r1 = ret.Error(1) - } - - return r0, r1 -} - // GetRepliesForExport provides a mock function with given fields: parentID func (_m *PostStore) GetRepliesForExport(parentID string) ([]*model.ReplyForExport, error) { ret := _m.Called(parentID) @@ -921,20 +895,6 @@ func (_m *PostStore) InvalidateLastPostTimeCache(channelID string) { _m.Called(channelID) } -// LogRecentSearch provides a mock function with given fields: userID, searchQuery, createAt -func (_m *PostStore) LogRecentSearch(userID string, searchQuery []byte, createAt int64) error { - ret := _m.Called(userID, searchQuery, createAt) - - var r0 error - if rf, ok := ret.Get(0).(func(string, []byte, int64) error); ok { - r0 = rf(userID, searchQuery, createAt) - } else { - r0 = ret.Error(0) - } - - return r0 -} - // Overwrite provides a mock function with given fields: post func (_m *PostStore) Overwrite(post *model.Post) (*model.Post, error) { ret := _m.Called(post) diff --git a/server/channels/store/timerlayer/timerlayer.go b/server/channels/store/timerlayer/timerlayer.go index 126a256445..4c54c34ac8 100644 --- a/server/channels/store/timerlayer/timerlayer.go +++ b/server/channels/store/timerlayer/timerlayer.go @@ -5813,22 +5813,6 @@ func (s *TimerLayerPostStore) GetPostsSinceForSync(options model.GetPostsSinceFo return result, resultVar1, err } -func (s *TimerLayerPostStore) GetRecentSearchesForUser(userID string) ([]*model.SearchParams, error) { - start := time.Now() - - result, err := s.PostStore.GetRecentSearchesForUser(userID) - - elapsed := float64(time.Since(start)) / float64(time.Second) - if s.Root.Metrics != nil { - success := "false" - if err == nil { - success = "true" - } - s.Root.Metrics.ObserveStoreMethodDuration("PostStore.GetRecentSearchesForUser", success, elapsed) - } - return result, err -} - func (s *TimerLayerPostStore) GetRepliesForExport(parentID string) ([]*model.ReplyForExport, error) { start := time.Now() @@ -5908,22 +5892,6 @@ func (s *TimerLayerPostStore) InvalidateLastPostTimeCache(channelID string) { } } -func (s *TimerLayerPostStore) LogRecentSearch(userID string, searchQuery []byte, createAt int64) error { - start := time.Now() - - err := s.PostStore.LogRecentSearch(userID, searchQuery, createAt) - - elapsed := float64(time.Since(start)) / float64(time.Second) - if s.Root.Metrics != nil { - success := "false" - if err == nil { - success = "true" - } - s.Root.Metrics.ObserveStoreMethodDuration("PostStore.LogRecentSearch", success, elapsed) - } - return err -} - func (s *TimerLayerPostStore) Overwrite(post *model.Post) (*model.Post, error) { start := time.Now() diff --git a/server/i18n/en.json b/server/i18n/en.json index a38bde850a..451fed068a 100644 --- a/server/i18n/en.json +++ b/server/i18n/en.json @@ -6403,10 +6403,6 @@ "id": "app.reaction.save.save.app_error", "translation": "Unable to save reaction." }, - { - "id": "app.recent_searches.app_error", - "translation": "Error fetching recent searches" - }, { "id": "app.recover.delete.app_error", "translation": "Unable to delete token." diff --git a/server/public/model/feature_flags.go b/server/public/model/feature_flags.go index 29ae7dafdc..4b79d48a3d 100644 --- a/server/public/model/feature_flags.go +++ b/server/public/model/feature_flags.go @@ -43,8 +43,6 @@ type FeatureFlags struct { InsightsEnabled bool - CommandPalette bool - PostPriority bool // Enable WYSIWYG text editor @@ -74,7 +72,6 @@ func (f *FeatureFlags) SetDefaults() { f.NormalizeLdapDNs = false f.GraphQL = false f.InsightsEnabled = false - f.CommandPalette = false f.CallsEnabled = true f.PeopleProduct = false f.DeprecateCloudFree = false diff --git a/server/public/model/post.go b/server/public/model/post.go index ce5963252d..a24798f886 100644 --- a/server/public/model/post.go +++ b/server/public/model/post.go @@ -77,11 +77,6 @@ const ( PostPropsPersistentNotifications = "persistent_notifications" ) -const ( - ModifierMessages string = "messages" - ModifierFiles string = "files" -) - type Post struct { Id string `json:"id"` CreateAt int64 `json:"create_at"` @@ -197,7 +192,6 @@ type SearchParameter struct { Page *int `json:"page"` PerPage *int `json:"per_page"` IncludeDeletedChannels *bool `json:"include_deleted_channels"` - Modifier *string `json:"modifier"` // whether it's messages or file } type AnalyticsPostCountsOptions struct { diff --git a/server/public/model/search_params.go b/server/public/model/search_params.go index c902ca2f43..bbb21b89dc 100644 --- a/server/public/model/search_params.go +++ b/server/public/model/search_params.go @@ -33,7 +33,7 @@ type SearchParams struct { IncludeDeletedChannels bool `json:"include_deleted_channels,omitempty"` TimeZoneOffset int `json:"timezone_offset,omitempty"` // True if this search doesn't originate from a "current user". - SearchWithoutUserId bool `json:"search_without_userid,omitempty"` + SearchWithoutUserId bool `json:"search_without_user_id,omitempty"` Modifier string `json:"modifier"` }