Remove command palette POC (#24044)
* Revert "POC: Cross-team recent search (#20027)" This reverts commitaa59c28b04, preserving a few code tidyings unrelated to the original PR. * Revert "Add feature flag for command palette (#20011)" This reverts commitc78c5ce3f3.
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
c35777194d
Коммит
89e65257a6
@@ -33,14 +33,13 @@ const maxMultipartFormDataBytes = 10 * 1024 // 10Kb
|
|||||||
|
|
||||||
func (api *API) InitFile() {
|
func (api *API) InitFile() {
|
||||||
api.BaseRoutes.Files.Handle("", api.APISessionRequired(uploadFileStream)).Methods("POST")
|
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("", api.APISessionRequiredTrustRequester(getFile)).Methods("GET")
|
||||||
api.BaseRoutes.File.Handle("/thumbnail", api.APISessionRequiredTrustRequester(getFileThumbnail)).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("/link", api.APISessionRequired(getFileLink)).Methods("GET")
|
||||||
api.BaseRoutes.File.Handle("/preview", api.APISessionRequiredTrustRequester(getFilePreview)).Methods("GET")
|
api.BaseRoutes.File.Handle("/preview", api.APISessionRequiredTrustRequester(getFilePreview)).Methods("GET")
|
||||||
api.BaseRoutes.File.Handle("/info", api.APISessionRequired(getFileInfo)).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")
|
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)
|
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()
|
c.RequireTeamId()
|
||||||
if c.Err != nil {
|
if c.Err != nil {
|
||||||
return
|
return
|
||||||
@@ -671,16 +670,6 @@ func searchFilesInTeam(c *Context, w http.ResponseWriter, r *http.Request) {
|
|||||||
return
|
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
|
var params model.SearchParameter
|
||||||
jsonErr := json.NewDecoder(r.Body).Decode(¶ms)
|
jsonErr := json.NewDecoder(r.Body).Decode(¶ms)
|
||||||
if jsonErr != nil {
|
if jsonErr != nil {
|
||||||
@@ -719,18 +708,9 @@ func searchFiles(c *Context, w http.ResponseWriter, r *http.Request, teamID stri
|
|||||||
includeDeletedChannels = *params.IncludeDeletedChannels
|
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()
|
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)
|
elapsedTime := float64(time.Since(startTime)) / float64(time.Second)
|
||||||
metrics := c.App.Metrics()
|
metrics := c.App.Metrics()
|
||||||
|
|||||||
@@ -773,18 +773,9 @@ func searchPosts(c *Context, w http.ResponseWriter, r *http.Request, teamId stri
|
|||||||
includeDeletedChannels = *params.IncludeDeletedChannels
|
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()
|
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)
|
elapsedTime := float64(time.Since(startTime)) / float64(time.Second)
|
||||||
metrics := c.App.Metrics()
|
metrics := c.App.Metrics()
|
||||||
|
|||||||
@@ -91,7 +91,6 @@ func (api *API) InitUser() {
|
|||||||
|
|
||||||
api.BaseRoutes.User.Handle("/uploads", api.APISessionRequired(getUploadsForUser)).Methods("GET")
|
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("/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")
|
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))
|
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))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -751,7 +751,6 @@ type AppIface interface {
|
|||||||
GetPublicChannelsByIdsForTeam(c request.CTX, teamID string, channelIDs []string) (model.ChannelList, *model.AppError)
|
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)
|
GetPublicChannelsForTeam(c request.CTX, teamID string, offset int, limit int) (model.ChannelList, *model.AppError)
|
||||||
GetReactionsForPost(postID string) ([]*model.Reaction, *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)
|
GetRecentlyActiveUsersForTeam(teamID string) (map[string]*model.User, *model.AppError)
|
||||||
GetRecentlyActiveUsersForTeamPage(teamID string, page, perPage int, asAdmin bool, viewRestrictions *model.ViewUsersRestrictions) ([]*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)
|
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)
|
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)
|
SearchEmoji(c request.CTX, name string, prefixOnly bool, limit int) ([]*model.Emoji, *model.AppError)
|
||||||
SearchEngine() *searchengine.Broker
|
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)
|
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)
|
SearchPostsInTeam(teamID string, paramsList []*model.SearchParams) (*model.PostList, *model.AppError)
|
||||||
SearchPrivateTeams(searchOpts *model.TeamSearch) ([]*model.Team, *model.AppError)
|
SearchPrivateTeams(searchOpts *model.TeamSearch) ([]*model.Team, *model.AppError)
|
||||||
SearchPublicTeams(searchOpts *model.TeamSearch) ([]*model.Team, *model.AppError)
|
SearchPublicTeams(searchOpts *model.TeamSearch) ([]*model.Team, *model.AppError)
|
||||||
|
|||||||
@@ -1363,7 +1363,7 @@ func populateZipfile(w *zip.Writer, fileDatas []model.FileData) error {
|
|||||||
return nil
|
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)
|
paramsList := model.ParseSearchParams(strings.TrimSpace(terms), timeZoneOffset)
|
||||||
includeDeleted := includeDeletedChannels && *a.Config().TeamSettings.ExperimentalViewArchivedChannels
|
includeDeleted := includeDeletedChannels && *a.Config().TeamSettings.ExperimentalViewArchivedChannels
|
||||||
|
|
||||||
@@ -1374,7 +1374,6 @@ func (a *App) SearchFilesInTeamForUser(c *request.Context, terms string, userId
|
|||||||
finalParamsList := []*model.SearchParams{}
|
finalParamsList := []*model.SearchParams{}
|
||||||
|
|
||||||
for _, params := range paramsList {
|
for _, params := range paramsList {
|
||||||
params.Modifier = modifier
|
|
||||||
params.OrTerms = isOrSearch
|
params.OrTerms = isOrSearch
|
||||||
params.IncludeDeletedChannels = includeDeleted
|
params.IncludeDeletedChannels = includeDeleted
|
||||||
// Don't allow users to search for "*"
|
// Don't allow users to search for "*"
|
||||||
|
|||||||
@@ -403,7 +403,7 @@ func TestSearchFilesInTeamForUser(t *testing.T) {
|
|||||||
|
|
||||||
page := 0
|
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.Nil(t, err)
|
||||||
require.NotNil(t, results)
|
require.NotNil(t, results)
|
||||||
@@ -424,7 +424,7 @@ func TestSearchFilesInTeamForUser(t *testing.T) {
|
|||||||
|
|
||||||
page := 1
|
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.Nil(t, err)
|
||||||
require.NotNil(t, results)
|
require.NotNil(t, results)
|
||||||
@@ -454,7 +454,7 @@ func TestSearchFilesInTeamForUser(t *testing.T) {
|
|||||||
th.App.Srv().Platform().SearchEngine.ElasticsearchEngine = nil
|
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.Nil(t, err)
|
||||||
require.NotNil(t, results)
|
require.NotNil(t, results)
|
||||||
@@ -482,7 +482,7 @@ func TestSearchFilesInTeamForUser(t *testing.T) {
|
|||||||
th.App.Srv().Platform().SearchEngine.ElasticsearchEngine = nil
|
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.Nil(t, err)
|
||||||
require.NotNil(t, results)
|
require.NotNil(t, results)
|
||||||
@@ -507,7 +507,7 @@ func TestSearchFilesInTeamForUser(t *testing.T) {
|
|||||||
th.App.Srv().Platform().SearchEngine.ElasticsearchEngine = nil
|
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.Nil(t, err)
|
||||||
require.NotNil(t, results)
|
require.NotNil(t, results)
|
||||||
@@ -540,7 +540,7 @@ func TestSearchFilesInTeamForUser(t *testing.T) {
|
|||||||
th.App.Srv().Platform().SearchEngine.ElasticsearchEngine = nil
|
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.Nil(t, err)
|
||||||
assert.Equal(t, []string{}, results.Order)
|
assert.Equal(t, []string{}, results.Order)
|
||||||
|
|||||||
@@ -8720,28 +8720,6 @@ func (a *OpenTracingAppLayer) GetReactionsForPost(postID string) ([]*model.React
|
|||||||
return resultVar0, resultVar1
|
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) {
|
func (a *OpenTracingAppLayer) GetRecentlyActiveUsersForTeam(teamID string) (map[string]*model.User, *model.AppError) {
|
||||||
origCtx := a.ctx
|
origCtx := a.ctx
|
||||||
span, newCtx := tracing.StartSpanWithParentByContext(a.ctx, "app.GetRecentlyActiveUsersForTeam")
|
span, newCtx := tracing.StartSpanWithParentByContext(a.ctx, "app.GetRecentlyActiveUsersForTeam")
|
||||||
@@ -15337,7 +15315,7 @@ func (a *OpenTracingAppLayer) SearchEngine() *searchengine.Broker {
|
|||||||
return resultVar0
|
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
|
origCtx := a.ctx
|
||||||
span, newCtx := tracing.StartSpanWithParentByContext(a.ctx, "app.SearchFilesInTeamForUser")
|
span, newCtx := tracing.StartSpanWithParentByContext(a.ctx, "app.SearchFilesInTeamForUser")
|
||||||
|
|
||||||
@@ -15349,7 +15327,7 @@ func (a *OpenTracingAppLayer) SearchFilesInTeamForUser(c *request.Context, terms
|
|||||||
}()
|
}()
|
||||||
|
|
||||||
defer span.Finish()
|
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 {
|
if resultVar1 != nil {
|
||||||
span.LogFields(spanlog.Error(resultVar1))
|
span.LogFields(spanlog.Error(resultVar1))
|
||||||
@@ -15381,7 +15359,7 @@ func (a *OpenTracingAppLayer) SearchGroupChannels(c request.CTX, userID string,
|
|||||||
return resultVar0, resultVar1
|
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
|
origCtx := a.ctx
|
||||||
span, newCtx := tracing.StartSpanWithParentByContext(a.ctx, "app.SearchPostsForUser")
|
span, newCtx := tracing.StartSpanWithParentByContext(a.ctx, "app.SearchPostsForUser")
|
||||||
|
|
||||||
@@ -15393,7 +15371,7 @@ func (a *OpenTracingAppLayer) SearchPostsForUser(c *request.Context, terms strin
|
|||||||
}()
|
}()
|
||||||
|
|
||||||
defer span.Finish()
|
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 {
|
if resultVar1 != nil {
|
||||||
span.LogFields(spanlog.Error(resultVar1))
|
span.LogFields(spanlog.Error(resultVar1))
|
||||||
|
|||||||
@@ -546,7 +546,7 @@ func (api *PluginAPI) SearchPostsInTeamForUser(teamID string, userID string, sea
|
|||||||
includeDeletedChannels = *searchParams.IncludeDeletedChannels
|
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 {
|
if results != nil {
|
||||||
results = results.ForPlugin()
|
results = results.ForPlugin()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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
|
var postSearchResults *model.PostSearchResults
|
||||||
paramsList := model.ParseSearchParams(strings.TrimSpace(terms), timeZoneOffset)
|
paramsList := model.ParseSearchParams(strings.TrimSpace(terms), timeZoneOffset)
|
||||||
includeDeleted := includeDeletedChannels && *a.Config().TeamSettings.ExperimentalViewArchivedChannels
|
includeDeleted := includeDeletedChannels && *a.Config().TeamSettings.ExperimentalViewArchivedChannels
|
||||||
@@ -1592,7 +1592,6 @@ func (a *App) SearchPostsForUser(c *request.Context, terms string, userID string
|
|||||||
finalParamsList := []*model.SearchParams{}
|
finalParamsList := []*model.SearchParams{}
|
||||||
|
|
||||||
for _, params := range paramsList {
|
for _, params := range paramsList {
|
||||||
params.Modifier = modifier
|
|
||||||
params.OrTerms = isOrSearch
|
params.OrTerms = isOrSearch
|
||||||
params.IncludeDeletedChannels = includeDeleted
|
params.IncludeDeletedChannels = includeDeleted
|
||||||
// Don't allow users to search for "*"
|
// 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
|
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) {
|
func (a *App) GetFileInfosForPostWithMigration(postID string, includeDeleted bool) ([]*model.FileInfo, *model.AppError) {
|
||||||
|
|
||||||
pchan := make(chan store.StoreResult, 1)
|
pchan := make(chan store.StoreResult, 1)
|
||||||
|
|||||||
@@ -1429,7 +1429,7 @@ func TestSearchPostsForUser(t *testing.T) {
|
|||||||
|
|
||||||
page := 0
|
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.Nil(t, err)
|
||||||
assert.Equal(t, []string{
|
assert.Equal(t, []string{
|
||||||
@@ -1449,7 +1449,7 @@ func TestSearchPostsForUser(t *testing.T) {
|
|||||||
|
|
||||||
page := 1
|
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.Nil(t, err)
|
||||||
assert.Equal(t, []string{}, results.Order)
|
assert.Equal(t, []string{}, results.Order)
|
||||||
@@ -1478,7 +1478,7 @@ func TestSearchPostsForUser(t *testing.T) {
|
|||||||
th.App.Srv().Platform().SearchEngine.ElasticsearchEngine = nil
|
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.Nil(t, err)
|
||||||
assert.Equal(t, resultsPage, results.Order)
|
assert.Equal(t, resultsPage, results.Order)
|
||||||
@@ -1505,7 +1505,7 @@ func TestSearchPostsForUser(t *testing.T) {
|
|||||||
th.App.Srv().Platform().SearchEngine.ElasticsearchEngine = nil
|
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.Nil(t, err)
|
||||||
assert.Equal(t, resultsPage, results.Order)
|
assert.Equal(t, resultsPage, results.Order)
|
||||||
@@ -1529,7 +1529,7 @@ func TestSearchPostsForUser(t *testing.T) {
|
|||||||
th.App.Srv().Platform().SearchEngine.ElasticsearchEngine = nil
|
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.Nil(t, err)
|
||||||
assert.Equal(t, []string{
|
assert.Equal(t, []string{
|
||||||
@@ -1561,7 +1561,7 @@ func TestSearchPostsForUser(t *testing.T) {
|
|||||||
th.App.Srv().Platform().SearchEngine.ElasticsearchEngine = nil
|
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.Nil(t, err)
|
||||||
assert.Equal(t, []string{}, results.Order)
|
assert.Equal(t, []string{}, results.Order)
|
||||||
|
|||||||
@@ -1 +1,2 @@
|
|||||||
|
-- This table is unused, and will be dropped in a future ESR.
|
||||||
DROP TABLE IF EXISTS RecentSearches;
|
DROP TABLE IF EXISTS RecentSearches;
|
||||||
@@ -1,3 +1,4 @@
|
|||||||
|
-- This table is unused, and will be dropped in a future ESR.
|
||||||
CREATE TABLE IF NOT EXISTS RecentSearches (
|
CREATE TABLE IF NOT EXISTS RecentSearches (
|
||||||
UserId CHAR(26),
|
UserId CHAR(26),
|
||||||
SearchPointer int,
|
SearchPointer int,
|
||||||
|
|||||||
@@ -1 +1,2 @@
|
|||||||
|
-- This table is unused, and will be dropped in a future ESR.
|
||||||
DROP TABLE IF EXISTS recentsearches;
|
DROP TABLE IF EXISTS recentsearches;
|
||||||
@@ -1,3 +1,4 @@
|
|||||||
|
-- This table is unused, and will be dropped in a future ESR.
|
||||||
CREATE TABLE IF NOT EXISTS recentsearches (
|
CREATE TABLE IF NOT EXISTS recentsearches (
|
||||||
userid CHAR(26),
|
userid CHAR(26),
|
||||||
searchpointer int,
|
searchpointer int,
|
||||||
|
|||||||
@@ -6422,24 +6422,6 @@ func (s *OpenTracingLayerPostStore) GetPostsSinceForSync(options model.GetPostsS
|
|||||||
return result, resultVar1, err
|
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) {
|
func (s *OpenTracingLayerPostStore) GetRepliesForExport(parentID string) ([]*model.ReplyForExport, error) {
|
||||||
origCtx := s.Root.Store.Context()
|
origCtx := s.Root.Store.Context()
|
||||||
span, newCtx := tracing.StartSpanWithParentByContext(s.Root.Store.Context(), "PostStore.GetRepliesForExport")
|
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) {
|
func (s *OpenTracingLayerPostStore) Overwrite(post *model.Post) (*model.Post, error) {
|
||||||
origCtx := s.Root.Store.Context()
|
origCtx := s.Root.Store.Context()
|
||||||
span, newCtx := tracing.StartSpanWithParentByContext(s.Root.Store.Context(), "PostStore.Overwrite")
|
span, newCtx := tracing.StartSpanWithParentByContext(s.Root.Store.Context(), "PostStore.Overwrite")
|
||||||
|
|||||||
@@ -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) {
|
func (s *RetryLayerPostStore) GetRepliesForExport(parentID string) ([]*model.ReplyForExport, error) {
|
||||||
|
|
||||||
tries := 0
|
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) {
|
func (s *RetryLayerPostStore) Overwrite(post *model.Post) (*model.Post, error) {
|
||||||
|
|
||||||
tries := 0
|
tries := 0
|
||||||
|
|||||||
@@ -1543,16 +1543,14 @@ func (s SqlChannelStore) getByName(teamId string, name string, includeDeleted bo
|
|||||||
query := s.getQueryBuilder().
|
query := s.getQueryBuilder().
|
||||||
Select("*").
|
Select("*").
|
||||||
From("Channels").
|
From("Channels").
|
||||||
Where(sq.Eq{"Name": name})
|
Where(sq.Eq{"Name": name}).
|
||||||
|
Where(sq.Or{
|
||||||
if !includeDeleted {
|
|
||||||
query = query.Where(sq.Eq{"DeleteAt": 0})
|
|
||||||
}
|
|
||||||
if teamId != "" {
|
|
||||||
query = query.Where(sq.Or{
|
|
||||||
sq.Eq{"TeamId": teamId},
|
sq.Eq{"TeamId": teamId},
|
||||||
sq.Eq{"TeamId": ""},
|
sq.Eq{"TeamId": ""},
|
||||||
})
|
})
|
||||||
|
|
||||||
|
if !includeDeleted {
|
||||||
|
query = query.Where(sq.Eq{"DeleteAt": 0})
|
||||||
}
|
}
|
||||||
channel := model.Channel{}
|
channel := model.Channel{}
|
||||||
|
|
||||||
|
|||||||
@@ -5,7 +5,6 @@ package sqlstore
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"database/sql"
|
"database/sql"
|
||||||
"encoding/json"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"regexp"
|
"regexp"
|
||||||
"strconv"
|
"strconv"
|
||||||
@@ -512,33 +511,12 @@ func (fs SqlFileInfoStore) Search(paramsList []*model.SearchParams, userId, team
|
|||||||
From("FileInfo").
|
From("FileInfo").
|
||||||
LeftJoin("Channels as C ON C.Id=FileInfo.ChannelId").
|
LeftJoin("Channels as C ON C.Id=FileInfo.ChannelId").
|
||||||
LeftJoin("ChannelMembers as CM ON C.Id=CM.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}).
|
Where(sq.Eq{"FileInfo.DeleteAt": 0}).
|
||||||
OrderBy("FileInfo.CreateAt DESC").
|
OrderBy("FileInfo.CreateAt DESC").
|
||||||
Limit(100)
|
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 {
|
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, " ")
|
params.Terms = removeNonAlphaNumericUnquotedTerms(params.Terms, " ")
|
||||||
|
|
||||||
if !params.IncludeDeletedChannels {
|
if !params.IncludeDeletedChannels {
|
||||||
|
|||||||
@@ -6,11 +6,9 @@ package sqlstore
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"database/sql"
|
"database/sql"
|
||||||
"encoding/json"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"reflect"
|
"reflect"
|
||||||
"regexp"
|
"regexp"
|
||||||
"strconv"
|
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
@@ -1923,13 +1921,11 @@ func (s *SqlPostStore) buildSearchPostFilterClause(teamID string, fromUsers []st
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Sub-query builder.
|
// Sub-query builder.
|
||||||
sb := s.getSubQueryBuilder().
|
sb := s.getSubQueryBuilder().Select("Id").From("Users, TeamMembers").Where(
|
||||||
Select("Id").
|
sq.And{
|
||||||
From("Users, TeamMembers").
|
sq.Eq{"TeamMembers.TeamId": teamID},
|
||||||
Where(sq.Expr("Users.Id = TeamMembers.UserId"))
|
sq.Expr("Users.Id = TeamMembers.UserId"),
|
||||||
if teamID != "" {
|
})
|
||||||
sb = sb.Where(sq.Eq{"TeamMembers.TeamId": teamID})
|
|
||||||
}
|
|
||||||
sb = s.buildSearchUserFilterClause(fromUsers, false, userByUsername, sb)
|
sb = s.buildSearchUserFilterClause(fromUsers, false, userByUsername, sb)
|
||||||
sb = s.buildSearchUserFilterClause(excludedUsers, true, userByUsername, sb)
|
sb = s.buildSearchUserFilterClause(excludedUsers, true, userByUsername, sb)
|
||||||
subQuery, subQueryArgs, err := sb.ToSql()
|
subQuery, subQueryArgs, err := sb.ToSql()
|
||||||
@@ -2710,7 +2706,7 @@ func (s *SqlPostStore) GetDirectPostParentsForExportAfter(limit int, afterId str
|
|||||||
}
|
}
|
||||||
|
|
||||||
//nolint:unparam
|
//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
|
// Since we don't support paging for DB search, we just return nothing for later pages
|
||||||
if page > 0 {
|
if page > 0 {
|
||||||
return model.MakePostSearchResults(model.NewPostList(), nil), nil
|
return model.MakePostSearchResults(model.NewPostList(), nil), nil
|
||||||
@@ -2720,22 +2716,11 @@ func (s *SqlPostStore) SearchPostsForUser(paramsList []*model.SearchParams, user
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
now := model.GetMillis()
|
var wg sync.WaitGroup
|
||||||
|
|
||||||
pchan := make(chan store.StoreResult, len(paramsList))
|
pchan := make(chan store.StoreResult, len(paramsList))
|
||||||
|
|
||||||
var wg sync.WaitGroup
|
|
||||||
for _, params := range paramsList {
|
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
|
// remove any unquoted term that contains only non-alphanumeric chars
|
||||||
// ex: abcd "**" && abc >> abcd "**" abc
|
// ex: abcd "**" && abc >> abcd "**" abc
|
||||||
params.Terms = removeNonAlphaNumericUnquotedTerms(params.Terms, " ")
|
params.Terms = removeNonAlphaNumericUnquotedTerms(params.Terms, " ")
|
||||||
@@ -2744,7 +2729,7 @@ func (s *SqlPostStore) SearchPostsForUser(paramsList []*model.SearchParams, user
|
|||||||
|
|
||||||
go func(params *model.SearchParams) {
|
go func(params *model.SearchParams) {
|
||||||
defer wg.Done()
|
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}
|
pchan <- store.StoreResult{Data: postList, NErr: err}
|
||||||
}(params)
|
}(params)
|
||||||
}
|
}
|
||||||
@@ -2767,103 +2752,6 @@ func (s *SqlPostStore) SearchPostsForUser(paramsList []*model.SearchParams, user
|
|||||||
return model.MakePostSearchResults(posts, nil), nil
|
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) {
|
func (s *SqlPostStore) GetOldestEntityCreationTime() (int64, error) {
|
||||||
query := s.getQueryBuilder().Select("MIN(min_createat) min_createat").
|
query := s.getQueryBuilder().Select("MIN(min_createat) min_createat").
|
||||||
Suffix(`FROM (
|
Suffix(`FROM (
|
||||||
|
|||||||
@@ -396,8 +396,6 @@ type PostStore interface {
|
|||||||
GetRepliesForExport(parentID string) ([]*model.ReplyForExport, error)
|
GetRepliesForExport(parentID string) ([]*model.ReplyForExport, error)
|
||||||
GetDirectPostParentsForExportAfter(limit int, afterID string) ([]*model.DirectPostForExport, error)
|
GetDirectPostParentsForExportAfter(limit int, afterID string) ([]*model.DirectPostForExport, error)
|
||||||
SearchPostsForUser(paramsList []*model.SearchParams, userID, teamID string, page, perPage int) (*model.PostSearchResults, 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)
|
GetOldestEntityCreationTime() (int64, error)
|
||||||
HasAutoResponsePostByUserSince(options model.GetPostsSinceOptions, userId string) (bool, error)
|
HasAutoResponsePostByUserSince(options model.GetPostsSinceOptions, userId string) (bool, error)
|
||||||
GetPostsSinceForSync(options model.GetPostsSinceForSyncOptions, cursor model.GetPostsSinceForSyncCursor, limit int) ([]*model.Post, model.GetPostsSinceForSyncCursor, error)
|
GetPostsSinceForSync(options model.GetPostsSinceForSyncOptions, cursor model.GetPostsSinceForSyncCursor, limit int) ([]*model.Post, model.GetPostsSinceForSyncCursor, error)
|
||||||
|
|||||||
@@ -788,32 +788,6 @@ func (_m *PostStore) GetPostsSinceForSync(options model.GetPostsSinceForSyncOpti
|
|||||||
return r0, r1, r2
|
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
|
// GetRepliesForExport provides a mock function with given fields: parentID
|
||||||
func (_m *PostStore) GetRepliesForExport(parentID string) ([]*model.ReplyForExport, error) {
|
func (_m *PostStore) GetRepliesForExport(parentID string) ([]*model.ReplyForExport, error) {
|
||||||
ret := _m.Called(parentID)
|
ret := _m.Called(parentID)
|
||||||
@@ -921,20 +895,6 @@ func (_m *PostStore) InvalidateLastPostTimeCache(channelID string) {
|
|||||||
_m.Called(channelID)
|
_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
|
// Overwrite provides a mock function with given fields: post
|
||||||
func (_m *PostStore) Overwrite(post *model.Post) (*model.Post, error) {
|
func (_m *PostStore) Overwrite(post *model.Post) (*model.Post, error) {
|
||||||
ret := _m.Called(post)
|
ret := _m.Called(post)
|
||||||
|
|||||||
@@ -5813,22 +5813,6 @@ func (s *TimerLayerPostStore) GetPostsSinceForSync(options model.GetPostsSinceFo
|
|||||||
return result, resultVar1, err
|
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) {
|
func (s *TimerLayerPostStore) GetRepliesForExport(parentID string) ([]*model.ReplyForExport, error) {
|
||||||
start := time.Now()
|
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) {
|
func (s *TimerLayerPostStore) Overwrite(post *model.Post) (*model.Post, error) {
|
||||||
start := time.Now()
|
start := time.Now()
|
||||||
|
|
||||||
|
|||||||
@@ -6403,10 +6403,6 @@
|
|||||||
"id": "app.reaction.save.save.app_error",
|
"id": "app.reaction.save.save.app_error",
|
||||||
"translation": "Unable to save reaction."
|
"translation": "Unable to save reaction."
|
||||||
},
|
},
|
||||||
{
|
|
||||||
"id": "app.recent_searches.app_error",
|
|
||||||
"translation": "Error fetching recent searches"
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
"id": "app.recover.delete.app_error",
|
"id": "app.recover.delete.app_error",
|
||||||
"translation": "Unable to delete token."
|
"translation": "Unable to delete token."
|
||||||
|
|||||||
@@ -43,8 +43,6 @@ type FeatureFlags struct {
|
|||||||
|
|
||||||
InsightsEnabled bool
|
InsightsEnabled bool
|
||||||
|
|
||||||
CommandPalette bool
|
|
||||||
|
|
||||||
PostPriority bool
|
PostPriority bool
|
||||||
|
|
||||||
// Enable WYSIWYG text editor
|
// Enable WYSIWYG text editor
|
||||||
@@ -74,7 +72,6 @@ func (f *FeatureFlags) SetDefaults() {
|
|||||||
f.NormalizeLdapDNs = false
|
f.NormalizeLdapDNs = false
|
||||||
f.GraphQL = false
|
f.GraphQL = false
|
||||||
f.InsightsEnabled = false
|
f.InsightsEnabled = false
|
||||||
f.CommandPalette = false
|
|
||||||
f.CallsEnabled = true
|
f.CallsEnabled = true
|
||||||
f.PeopleProduct = false
|
f.PeopleProduct = false
|
||||||
f.DeprecateCloudFree = false
|
f.DeprecateCloudFree = false
|
||||||
|
|||||||
@@ -77,11 +77,6 @@ const (
|
|||||||
PostPropsPersistentNotifications = "persistent_notifications"
|
PostPropsPersistentNotifications = "persistent_notifications"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
|
||||||
ModifierMessages string = "messages"
|
|
||||||
ModifierFiles string = "files"
|
|
||||||
)
|
|
||||||
|
|
||||||
type Post struct {
|
type Post struct {
|
||||||
Id string `json:"id"`
|
Id string `json:"id"`
|
||||||
CreateAt int64 `json:"create_at"`
|
CreateAt int64 `json:"create_at"`
|
||||||
@@ -197,7 +192,6 @@ type SearchParameter struct {
|
|||||||
Page *int `json:"page"`
|
Page *int `json:"page"`
|
||||||
PerPage *int `json:"per_page"`
|
PerPage *int `json:"per_page"`
|
||||||
IncludeDeletedChannels *bool `json:"include_deleted_channels"`
|
IncludeDeletedChannels *bool `json:"include_deleted_channels"`
|
||||||
Modifier *string `json:"modifier"` // whether it's messages or file
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type AnalyticsPostCountsOptions struct {
|
type AnalyticsPostCountsOptions struct {
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ type SearchParams struct {
|
|||||||
IncludeDeletedChannels bool `json:"include_deleted_channels,omitempty"`
|
IncludeDeletedChannels bool `json:"include_deleted_channels,omitempty"`
|
||||||
TimeZoneOffset int `json:"timezone_offset,omitempty"`
|
TimeZoneOffset int `json:"timezone_offset,omitempty"`
|
||||||
// True if this search doesn't originate from a "current user".
|
// 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"`
|
Modifier string `json:"modifier"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user