Poststore migration part3 (#15505)
* Migration completed * Order in translations file * Fix: lints * Trigger CI * Fix message key * Change mlog.Error for mlog.Warn * Fix imports * Adding translations needed for EE * Trigger CI * Fix merge with master Co-authored-by: Agniva De Sarker <agnivade@yahoo.co.in> Co-authored-by: Mattermod <mattermod@users.noreply.github.com>
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
cd7d68effb
Коммит
8118cac350
@@ -79,7 +79,7 @@ func (a *App) GetAnalytics(name string, teamId string) (model.AnalyticsRows, *mo
|
||||
postChan = make(chan store.StoreResult, 1)
|
||||
go func() {
|
||||
count, err2 := a.Srv().Store.Post().AnalyticsPostCount(teamId, false, false)
|
||||
postChan <- store.StoreResult{Data: count, Err: err2}
|
||||
postChan <- store.StoreResult{Data: count, NErr: err2}
|
||||
close(postChan)
|
||||
}()
|
||||
}
|
||||
@@ -121,8 +121,8 @@ func (a *App) GetAnalytics(name string, teamId string) (model.AnalyticsRows, *mo
|
||||
rows[2].Value = -1
|
||||
} else {
|
||||
r = <-postChan
|
||||
if r.Err != nil {
|
||||
return nil, r.Err
|
||||
if r.NErr != nil {
|
||||
return nil, model.NewAppError("GetAnalytics", "app.post.analytics_posts_count.app_error", nil, r.NErr.Error(), http.StatusInternalServerError)
|
||||
}
|
||||
rows[2].Value = float64(r.Data.(int64))
|
||||
}
|
||||
@@ -198,28 +198,43 @@ func (a *App) GetAnalytics(name string, teamId string) (model.AnalyticsRows, *mo
|
||||
rows := model.AnalyticsRows{&model.AnalyticsRow{Name: "", Value: -1}}
|
||||
return rows, nil
|
||||
}
|
||||
return a.Srv().Store.Post().AnalyticsPostCountsByDay(&model.AnalyticsPostCountsOptions{
|
||||
analyticsRows, nErr := a.Srv().Store.Post().AnalyticsPostCountsByDay(&model.AnalyticsPostCountsOptions{
|
||||
TeamId: teamId,
|
||||
BotsOnly: true,
|
||||
YesterdayOnly: false,
|
||||
})
|
||||
if nErr != nil {
|
||||
return nil, model.NewAppError("GetAnalytics", "app.post.analytics_posts_count_by_day.app_error", nil, nErr.Error(), http.StatusInternalServerError)
|
||||
}
|
||||
|
||||
return analyticsRows, nil
|
||||
} else if name == "post_counts_day" {
|
||||
if skipIntensiveQueries {
|
||||
rows := model.AnalyticsRows{&model.AnalyticsRow{Name: "", Value: -1}}
|
||||
return rows, nil
|
||||
}
|
||||
return a.Srv().Store.Post().AnalyticsPostCountsByDay(&model.AnalyticsPostCountsOptions{
|
||||
analyticsRows, nErr := a.Srv().Store.Post().AnalyticsPostCountsByDay(&model.AnalyticsPostCountsOptions{
|
||||
TeamId: teamId,
|
||||
BotsOnly: false,
|
||||
YesterdayOnly: false,
|
||||
})
|
||||
if nErr != nil {
|
||||
return nil, model.NewAppError("GetAnalytics", "app.post.analytics_posts_count_by_day.app_error", nil, nErr.Error(), http.StatusInternalServerError)
|
||||
}
|
||||
|
||||
return analyticsRows, nil
|
||||
} else if name == "user_counts_with_posts_day" {
|
||||
if skipIntensiveQueries {
|
||||
rows := model.AnalyticsRows{&model.AnalyticsRow{Name: "", Value: -1}}
|
||||
return rows, nil
|
||||
}
|
||||
|
||||
return a.Srv().Store.Post().AnalyticsUserCountsWithPostsByDay(teamId)
|
||||
analyticsRows, nErr := a.Srv().Store.Post().AnalyticsUserCountsWithPostsByDay(teamId)
|
||||
if nErr != nil {
|
||||
return nil, model.NewAppError("GetAnalytics", "app.post.analytics_user_counts_posts_by_day.app_error", nil, nErr.Error(), http.StatusInternalServerError)
|
||||
}
|
||||
|
||||
return analyticsRows, nil
|
||||
} else if name == "extra_counts" {
|
||||
var rows model.AnalyticsRows = make([]*model.AnalyticsRow, 6)
|
||||
rows[0] = &model.AnalyticsRow{Name: "file_post_count", Value: 0}
|
||||
@@ -264,14 +279,14 @@ func (a *App) GetAnalytics(name string, teamId string) (model.AnalyticsRows, *mo
|
||||
fileChan = make(chan store.StoreResult, 1)
|
||||
go func() {
|
||||
count, err2 := a.Srv().Store.Post().AnalyticsPostCount(teamId, true, false)
|
||||
fileChan <- store.StoreResult{Data: count, Err: err2}
|
||||
fileChan <- store.StoreResult{Data: count, NErr: err2}
|
||||
close(fileChan)
|
||||
}()
|
||||
|
||||
hashtagChan = make(chan store.StoreResult, 1)
|
||||
go func() {
|
||||
count, err2 := a.Srv().Store.Post().AnalyticsPostCount(teamId, false, true)
|
||||
hashtagChan <- store.StoreResult{Data: count, Err: err2}
|
||||
hashtagChan <- store.StoreResult{Data: count, NErr: err2}
|
||||
close(hashtagChan)
|
||||
}()
|
||||
}
|
||||
@@ -280,8 +295,8 @@ func (a *App) GetAnalytics(name string, teamId string) (model.AnalyticsRows, *mo
|
||||
rows[0].Value = -1
|
||||
} else {
|
||||
r := <-fileChan
|
||||
if r.Err != nil {
|
||||
return nil, r.Err
|
||||
if r.NErr != nil {
|
||||
return nil, model.NewAppError("GetAnalytics", "app.post.analytics_posts_count.app_error", nil, r.NErr.Error(), http.StatusInternalServerError)
|
||||
}
|
||||
rows[0].Value = float64(r.Data.(int64))
|
||||
}
|
||||
@@ -290,8 +305,8 @@ func (a *App) GetAnalytics(name string, teamId string) (model.AnalyticsRows, *mo
|
||||
rows[1].Value = -1
|
||||
} else {
|
||||
r := <-hashtagChan
|
||||
if r.Err != nil {
|
||||
return nil, r.Err
|
||||
if r.NErr != nil {
|
||||
return nil, model.NewAppError("GetAnalytics", "app.post.analytics_posts_count.app_error", nil, r.NErr.Error(), http.StatusInternalServerError)
|
||||
}
|
||||
rows[1].Value = float64(r.Data.(int64))
|
||||
}
|
||||
|
||||
@@ -596,8 +596,8 @@ func TestAddChannelMemberNoUserRequestor(t *testing.T) {
|
||||
}
|
||||
assert.Equal(t, groupUserIds, channelMemberHistoryUserIds)
|
||||
|
||||
postList, err := th.App.Srv().Store.Post().GetPosts(model.GetPostsOptions{ChannelId: channel.Id, Page: 0, PerPage: 1}, false)
|
||||
require.Nil(t, err)
|
||||
postList, nErr := th.App.Srv().Store.Post().GetPosts(model.GetPostsOptions{ChannelId: channel.Id, Page: 0, PerPage: 1}, false)
|
||||
require.Nil(t, nErr)
|
||||
|
||||
if assert.Len(t, postList.Order, 1) {
|
||||
post := postList.Posts[postList.Order[0]]
|
||||
|
||||
@@ -338,9 +338,9 @@ func (a *App) exportAllPosts(writer io.Writer) *model.AppError {
|
||||
afterId := strings.Repeat("0", 26)
|
||||
|
||||
for {
|
||||
posts, err := a.Srv().Store.Post().GetParentsForExportAfter(1000, afterId)
|
||||
if err != nil {
|
||||
return err
|
||||
posts, nErr := a.Srv().Store.Post().GetParentsForExportAfter(1000, afterId)
|
||||
if nErr != nil {
|
||||
return model.NewAppError("exportAllPosts", "app.post.get_posts.app_error", nil, nErr.Error(), http.StatusInternalServerError)
|
||||
}
|
||||
|
||||
if len(posts) == 0 {
|
||||
@@ -357,6 +357,7 @@ func (a *App) exportAllPosts(writer io.Writer) *model.AppError {
|
||||
|
||||
postLine := ImportLineForPost(post)
|
||||
|
||||
var err *model.AppError
|
||||
postLine.Post.Replies, err = a.buildPostReplies(post.Id)
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -380,17 +381,18 @@ func (a *App) exportAllPosts(writer io.Writer) *model.AppError {
|
||||
func (a *App) buildPostReplies(postId string) (*[]ReplyImportData, *model.AppError) {
|
||||
var replies []ReplyImportData
|
||||
|
||||
replyPosts, err := a.Srv().Store.Post().GetRepliesForExport(postId)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
replyPosts, nErr := a.Srv().Store.Post().GetRepliesForExport(postId)
|
||||
if nErr != nil {
|
||||
return nil, model.NewAppError("buildPostReplies", "app.post.get_posts.app_error", nil, nErr.Error(), http.StatusInternalServerError)
|
||||
}
|
||||
|
||||
for _, reply := range replyPosts {
|
||||
replyImportObject := ImportReplyFromPost(reply)
|
||||
if reply.HasReactions {
|
||||
replyImportObject.Reactions, err = a.BuildPostReactions(reply.Id)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
var appErr *model.AppError
|
||||
replyImportObject.Reactions, appErr = a.BuildPostReactions(reply.Id)
|
||||
if appErr != nil {
|
||||
return nil, appErr
|
||||
}
|
||||
}
|
||||
replies = append(replies, *replyImportObject)
|
||||
@@ -545,7 +547,7 @@ func (a *App) exportAllDirectPosts(writer io.Writer) *model.AppError {
|
||||
for {
|
||||
posts, err := a.Srv().Store.Post().GetDirectPostParentsForExportAfter(1000, afterId)
|
||||
if err != nil {
|
||||
return err
|
||||
return model.NewAppError("exportAllDirectPosts", "app.post.get_direct_posts.app_error", nil, err.Error(), http.StatusInternalServerError)
|
||||
}
|
||||
|
||||
if len(posts) == 0 {
|
||||
|
||||
@@ -533,8 +533,8 @@ func TestExportDMPostWithSelf(t *testing.T) {
|
||||
err := th1.App.BulkExport(&b, "somefile", "somePath", "someDir")
|
||||
require.Nil(t, err)
|
||||
|
||||
posts, err := th1.App.Srv().Store.Post().GetDirectPostParentsForExportAfter(1000, "0000000")
|
||||
require.Nil(t, err)
|
||||
posts, nErr := th1.App.Srv().Store.Post().GetDirectPostParentsForExportAfter(1000, "0000000")
|
||||
require.Nil(t, nErr)
|
||||
assert.Equal(t, 1, len(posts))
|
||||
|
||||
th1.TearDown()
|
||||
@@ -542,8 +542,8 @@ func TestExportDMPostWithSelf(t *testing.T) {
|
||||
th2 := Setup(t)
|
||||
defer th2.TearDown()
|
||||
|
||||
posts, err = th2.App.Srv().Store.Post().GetDirectPostParentsForExportAfter(1000, "0000000")
|
||||
require.Nil(t, err)
|
||||
posts, nErr = th2.App.Srv().Store.Post().GetDirectPostParentsForExportAfter(1000, "0000000")
|
||||
require.Nil(t, nErr)
|
||||
assert.Equal(t, 0, len(posts))
|
||||
|
||||
// import the exported posts
|
||||
@@ -551,8 +551,8 @@ func TestExportDMPostWithSelf(t *testing.T) {
|
||||
assert.Nil(t, err)
|
||||
assert.Equal(t, 0, i)
|
||||
|
||||
posts, err = th2.App.Srv().Store.Post().GetDirectPostParentsForExportAfter(1000, "0000000")
|
||||
require.Nil(t, err)
|
||||
posts, nErr = th2.App.Srv().Store.Post().GetDirectPostParentsForExportAfter(1000, "0000000")
|
||||
require.Nil(t, nErr)
|
||||
assert.Equal(t, 1, len(posts))
|
||||
assert.Equal(t, 1, len((*posts[0].ChannelMembers)))
|
||||
assert.Equal(t, th1.BasicUser.Username, (*posts[0].ChannelMembers)[0])
|
||||
|
||||
@@ -1031,9 +1031,9 @@ func (a *App) importReplies(data []ReplyImportData, post *model.Post, teamId str
|
||||
user := users[*replyData.User]
|
||||
|
||||
// Check if this post already exists.
|
||||
replies, err := a.Srv().Store.Post().GetPostsCreatedAt(post.ChannelId, *replyData.CreateAt)
|
||||
if err != nil {
|
||||
return err
|
||||
replies, nErr := a.Srv().Store.Post().GetPostsCreatedAt(post.ChannelId, *replyData.CreateAt)
|
||||
if nErr != nil {
|
||||
return model.NewAppError("importReplies", "app.post.get_posts_created_at.app_error", nil, nErr.Error(), http.StatusInternalServerError)
|
||||
}
|
||||
|
||||
var reply *model.Post
|
||||
@@ -1091,8 +1091,8 @@ func (a *App) importReplies(data []ReplyImportData, post *model.Post, teamId str
|
||||
}
|
||||
}
|
||||
|
||||
if _, _, err := a.Srv().Store.Post().OverwriteMultiple(postsForOverwriteList); err != nil {
|
||||
return err
|
||||
if _, _, nErr := a.Srv().Store.Post().OverwriteMultiple(postsForOverwriteList); nErr != nil {
|
||||
return model.NewAppError("importReplies", "app.post.overwrite.app_error", nil, nErr.Error(), http.StatusInternalServerError)
|
||||
}
|
||||
|
||||
for _, postWithData := range postsWithData {
|
||||
@@ -1278,9 +1278,9 @@ func (a *App) importMultiplePostLines(lines []LineImportWorkerData, dryRun bool)
|
||||
user := users[*line.Post.User]
|
||||
|
||||
// Check if this post already exists.
|
||||
posts, appErr := a.Srv().Store.Post().GetPostsCreatedAt(channel.Id, *line.Post.CreateAt)
|
||||
if appErr != nil {
|
||||
return line.LineNumber, appErr
|
||||
posts, nErr := a.Srv().Store.Post().GetPostsCreatedAt(channel.Id, *line.Post.CreateAt)
|
||||
if nErr != nil {
|
||||
return line.LineNumber, model.NewAppError("importMultiplePostLines", "app.post.get_posts_created_at.app_error", nil, nErr.Error(), http.StatusInternalServerError)
|
||||
}
|
||||
|
||||
var post *model.Post
|
||||
@@ -1357,10 +1357,10 @@ func (a *App) importMultiplePostLines(lines []LineImportWorkerData, dryRun bool)
|
||||
if idx != -1 && idx < len(postsForOverwriteList) {
|
||||
post := postsForOverwriteList[idx]
|
||||
if lineNumber, ok := postsForOverwriteMap[getPostStrID(post)]; ok {
|
||||
return lineNumber, err
|
||||
return lineNumber, model.NewAppError("importMultiplePostLines", "app.post.overwrite.app_error", nil, err.Error(), http.StatusInternalServerError)
|
||||
}
|
||||
}
|
||||
return 0, err
|
||||
return 0, model.NewAppError("importMultiplePostLines", "app.post.overwrite.app_error", nil, err.Error(), http.StatusInternalServerError)
|
||||
}
|
||||
|
||||
for _, postWithData := range postsWithData {
|
||||
@@ -1574,9 +1574,9 @@ func (a *App) importMultipleDirectPostLines(lines []LineImportWorkerData, dryRun
|
||||
user := users[*line.DirectPost.User]
|
||||
|
||||
// Check if this post already exists.
|
||||
posts, err := a.Srv().Store.Post().GetPostsCreatedAt(channel.Id, *line.DirectPost.CreateAt)
|
||||
if err != nil {
|
||||
return line.LineNumber, err
|
||||
posts, nErr := a.Srv().Store.Post().GetPostsCreatedAt(channel.Id, *line.DirectPost.CreateAt)
|
||||
if nErr != nil {
|
||||
return line.LineNumber, model.NewAppError("BulkImport", "app.post.get_posts_created_at.app_error", nil, nErr.Error(), http.StatusInternalServerError)
|
||||
}
|
||||
|
||||
var post *model.Post
|
||||
@@ -1652,10 +1652,10 @@ func (a *App) importMultipleDirectPostLines(lines []LineImportWorkerData, dryRun
|
||||
if idx != -1 && idx < len(postsForOverwriteList) {
|
||||
post := postsForOverwriteList[idx]
|
||||
if lineNumber, ok := postsForOverwriteMap[getPostStrID(post)]; ok {
|
||||
return lineNumber, err
|
||||
return lineNumber, model.NewAppError("importMultiplePostLines", "app.post.overwrite.app_error", nil, err.Error(), http.StatusInternalServerError)
|
||||
}
|
||||
}
|
||||
return 0, err
|
||||
return 0, model.NewAppError("importMultiplePostLines", "app.post.overwrite.app_error", nil, err.Error(), http.StatusInternalServerError)
|
||||
}
|
||||
|
||||
for _, postWithData := range postsWithData {
|
||||
|
||||
@@ -1958,8 +1958,8 @@ func TestImportimportMultiplePostLines(t *testing.T) {
|
||||
require.Nil(t, err, "Failed to get user from database.")
|
||||
|
||||
// Count the number of posts in the testing team.
|
||||
initialPostCount, err := th.App.Srv().Store.Post().AnalyticsPostCount(team.Id, false, false)
|
||||
require.Nil(t, err)
|
||||
initialPostCount, nErr := th.App.Srv().Store.Post().AnalyticsPostCount(team.Id, false, false)
|
||||
require.Nil(t, nErr)
|
||||
|
||||
// Try adding an invalid post in dry run mode.
|
||||
data := LineImportWorkerData{
|
||||
@@ -2092,8 +2092,8 @@ func TestImportimportMultiplePostLines(t *testing.T) {
|
||||
AssertAllPostsCount(t, th.App, initialPostCount, 1, team.Id)
|
||||
|
||||
// Check the post values.
|
||||
posts, err := th.App.Srv().Store.Post().GetPostsCreatedAt(channel.Id, time)
|
||||
require.Nil(t, err)
|
||||
posts, nErr := th.App.Srv().Store.Post().GetPostsCreatedAt(channel.Id, time)
|
||||
require.Nil(t, nErr)
|
||||
|
||||
require.Len(t, posts, 1, "Unexpected number of posts found.")
|
||||
|
||||
@@ -2120,8 +2120,8 @@ func TestImportimportMultiplePostLines(t *testing.T) {
|
||||
AssertAllPostsCount(t, th.App, initialPostCount, 1, team.Id)
|
||||
|
||||
// Check the post values.
|
||||
posts, err = th.App.Srv().Store.Post().GetPostsCreatedAt(channel.Id, time)
|
||||
require.Nil(t, err)
|
||||
posts, nErr = th.App.Srv().Store.Post().GetPostsCreatedAt(channel.Id, time)
|
||||
require.Nil(t, nErr)
|
||||
|
||||
require.Len(t, posts, 1, "Unexpected number of posts found.")
|
||||
|
||||
@@ -2185,8 +2185,8 @@ func TestImportimportMultiplePostLines(t *testing.T) {
|
||||
assert.Equal(t, 0, errLine)
|
||||
AssertAllPostsCount(t, th.App, initialPostCount, 4, team.Id)
|
||||
|
||||
posts, err = th.App.Srv().Store.Post().GetPostsCreatedAt(channel.Id, hashtagTime)
|
||||
require.Nil(t, err)
|
||||
posts, nErr = th.App.Srv().Store.Post().GetPostsCreatedAt(channel.Id, hashtagTime)
|
||||
require.Nil(t, nErr)
|
||||
|
||||
require.Len(t, posts, 1, "Unexpected number of posts found.")
|
||||
|
||||
@@ -2230,8 +2230,8 @@ func TestImportimportMultiplePostLines(t *testing.T) {
|
||||
AssertAllPostsCount(t, th.App, initialPostCount, 5, team.Id)
|
||||
|
||||
// Check the post values.
|
||||
posts, err = th.App.Srv().Store.Post().GetPostsCreatedAt(channel.Id, flagsTime)
|
||||
require.Nil(t, err)
|
||||
posts, nErr = th.App.Srv().Store.Post().GetPostsCreatedAt(channel.Id, flagsTime)
|
||||
require.Nil(t, nErr)
|
||||
|
||||
require.Len(t, posts, 1, "Unexpected number of posts found.")
|
||||
|
||||
@@ -2269,8 +2269,8 @@ func TestImportimportMultiplePostLines(t *testing.T) {
|
||||
AssertAllPostsCount(t, th.App, initialPostCount, 6, team.Id)
|
||||
|
||||
// Check the post values.
|
||||
posts, err = th.App.Srv().Store.Post().GetPostsCreatedAt(channel.Id, reactionPostTime)
|
||||
require.Nil(t, err)
|
||||
posts, nErr = th.App.Srv().Store.Post().GetPostsCreatedAt(channel.Id, reactionPostTime)
|
||||
require.Nil(t, nErr)
|
||||
|
||||
require.Len(t, posts, 1, "Unexpected number of posts found.")
|
||||
|
||||
@@ -2310,8 +2310,8 @@ func TestImportimportMultiplePostLines(t *testing.T) {
|
||||
AssertAllPostsCount(t, th.App, initialPostCount, 8, team.Id)
|
||||
|
||||
// Check the post values.
|
||||
posts, err = th.App.Srv().Store.Post().GetPostsCreatedAt(channel.Id, replyPostTime)
|
||||
require.Nil(t, err)
|
||||
posts, nErr = th.App.Srv().Store.Post().GetPostsCreatedAt(channel.Id, replyPostTime)
|
||||
require.Nil(t, nErr)
|
||||
|
||||
require.Len(t, posts, 1, "Unexpected number of posts found.")
|
||||
|
||||
@@ -2320,8 +2320,8 @@ func TestImportimportMultiplePostLines(t *testing.T) {
|
||||
require.False(t, postBool, "Post properties not as expected")
|
||||
|
||||
// Check the reply values.
|
||||
replies, err := th.App.Srv().Store.Post().GetPostsCreatedAt(channel.Id, replyTime)
|
||||
require.Nil(t, err)
|
||||
replies, nErr := th.App.Srv().Store.Post().GetPostsCreatedAt(channel.Id, replyTime)
|
||||
require.Nil(t, nErr)
|
||||
|
||||
require.Len(t, replies, 1, "Unexpected number of posts found.")
|
||||
|
||||
@@ -2447,8 +2447,8 @@ func TestImportImportPost(t *testing.T) {
|
||||
require.Nil(t, appErr, "Failed to get user from database.")
|
||||
|
||||
// Count the number of posts in the testing team.
|
||||
initialPostCount, appErr := th.App.Srv().Store.Post().AnalyticsPostCount(team.Id, false, false)
|
||||
require.Nil(t, appErr)
|
||||
initialPostCount, nErr := th.App.Srv().Store.Post().AnalyticsPostCount(team.Id, false, false)
|
||||
require.Nil(t, nErr)
|
||||
|
||||
time := model.GetMillis()
|
||||
hashtagTime := time + 2
|
||||
@@ -2585,8 +2585,8 @@ func TestImportImportPost(t *testing.T) {
|
||||
AssertAllPostsCount(t, th.App, initialPostCount, 1, team.Id)
|
||||
|
||||
// Check the post values.
|
||||
posts, err := th.App.Srv().Store.Post().GetPostsCreatedAt(channel.Id, time)
|
||||
require.Nil(t, err)
|
||||
posts, nErr := th.App.Srv().Store.Post().GetPostsCreatedAt(channel.Id, time)
|
||||
require.Nil(t, nErr)
|
||||
|
||||
require.Len(t, posts, 1, "Unexpected number of posts found.")
|
||||
|
||||
@@ -2614,8 +2614,8 @@ func TestImportImportPost(t *testing.T) {
|
||||
AssertAllPostsCount(t, th.App, initialPostCount, 1, team.Id)
|
||||
|
||||
// Check the post values.
|
||||
posts, err := th.App.Srv().Store.Post().GetPostsCreatedAt(channel.Id, time)
|
||||
require.Nil(t, err)
|
||||
posts, nErr := th.App.Srv().Store.Post().GetPostsCreatedAt(channel.Id, time)
|
||||
require.Nil(t, nErr)
|
||||
|
||||
require.Len(t, posts, 1, "Unexpected number of posts found.")
|
||||
|
||||
@@ -2681,8 +2681,8 @@ func TestImportImportPost(t *testing.T) {
|
||||
assert.Equal(t, 0, errLine)
|
||||
AssertAllPostsCount(t, th.App, initialPostCount, 4, team.Id)
|
||||
|
||||
posts, err := th.App.Srv().Store.Post().GetPostsCreatedAt(channel.Id, hashtagTime)
|
||||
require.Nil(t, err)
|
||||
posts, nErr := th.App.Srv().Store.Post().GetPostsCreatedAt(channel.Id, hashtagTime)
|
||||
require.Nil(t, nErr)
|
||||
|
||||
require.Len(t, posts, 1, "Unexpected number of posts found.")
|
||||
|
||||
@@ -2719,8 +2719,8 @@ func TestImportImportPost(t *testing.T) {
|
||||
AssertAllPostsCount(t, th.App, initialPostCount, 5, team.Id)
|
||||
|
||||
// Check the post values.
|
||||
posts, err := th.App.Srv().Store.Post().GetPostsCreatedAt(channel.Id, flagsTime)
|
||||
require.Nil(t, err)
|
||||
posts, nErr := th.App.Srv().Store.Post().GetPostsCreatedAt(channel.Id, flagsTime)
|
||||
require.Nil(t, nErr)
|
||||
|
||||
require.Len(t, posts, 1, "Unexpected number of posts found.")
|
||||
|
||||
@@ -2759,8 +2759,8 @@ func TestImportImportPost(t *testing.T) {
|
||||
AssertAllPostsCount(t, th.App, initialPostCount, 6, team.Id)
|
||||
|
||||
// Check the post values.
|
||||
posts, err := th.App.Srv().Store.Post().GetPostsCreatedAt(channel.Id, reactionPostTime)
|
||||
require.Nil(t, err)
|
||||
posts, nErr := th.App.Srv().Store.Post().GetPostsCreatedAt(channel.Id, reactionPostTime)
|
||||
require.Nil(t, nErr)
|
||||
|
||||
require.Len(t, posts, 1, "Unexpected number of posts found.")
|
||||
|
||||
@@ -2799,8 +2799,8 @@ func TestImportImportPost(t *testing.T) {
|
||||
AssertAllPostsCount(t, th.App, initialPostCount, 8, team.Id)
|
||||
|
||||
// Check the post values.
|
||||
posts, err := th.App.Srv().Store.Post().GetPostsCreatedAt(channel.Id, replyPostTime)
|
||||
require.Nil(t, err)
|
||||
posts, nErr := th.App.Srv().Store.Post().GetPostsCreatedAt(channel.Id, replyPostTime)
|
||||
require.Nil(t, nErr)
|
||||
|
||||
require.Len(t, posts, 1, "Unexpected number of posts found.")
|
||||
|
||||
@@ -2809,8 +2809,8 @@ func TestImportImportPost(t *testing.T) {
|
||||
require.False(t, postBool, "Post properties not as expected")
|
||||
|
||||
// Check the reply values.
|
||||
replies, err := th.App.Srv().Store.Post().GetPostsCreatedAt(channel.Id, replyTime)
|
||||
require.Nil(t, err)
|
||||
replies, nErr := th.App.Srv().Store.Post().GetPostsCreatedAt(channel.Id, replyTime)
|
||||
require.Nil(t, nErr)
|
||||
|
||||
require.Len(t, replies, 1, "Unexpected number of posts found.")
|
||||
|
||||
@@ -3087,8 +3087,8 @@ func TestImportImportDirectPost(t *testing.T) {
|
||||
directChannel = channel
|
||||
|
||||
// Get the number of posts in the system.
|
||||
result, appErr := th.App.Srv().Store.Post().AnalyticsPostCount("", false, false)
|
||||
require.Nil(t, appErr)
|
||||
result, err := th.App.Srv().Store.Post().AnalyticsPostCount("", false, false)
|
||||
require.Nil(t, err)
|
||||
initialPostCount := result
|
||||
initialDate := model.GetMillis()
|
||||
|
||||
@@ -3175,8 +3175,8 @@ func TestImportImportDirectPost(t *testing.T) {
|
||||
AssertAllPostsCount(t, th.App, initialPostCount, 1, "")
|
||||
|
||||
// Check the post values.
|
||||
posts, err := th.App.Srv().Store.Post().GetPostsCreatedAt(directChannel.Id, *data.DirectPost.CreateAt)
|
||||
require.Nil(t, err)
|
||||
posts, nErr := th.App.Srv().Store.Post().GetPostsCreatedAt(directChannel.Id, *data.DirectPost.CreateAt)
|
||||
require.Nil(t, nErr)
|
||||
require.Len(t, posts, 1)
|
||||
|
||||
post := posts[0]
|
||||
@@ -3206,8 +3206,8 @@ func TestImportImportDirectPost(t *testing.T) {
|
||||
AssertAllPostsCount(t, th.App, initialPostCount, 1, "")
|
||||
|
||||
// Check the post values.
|
||||
posts, err := th.App.Srv().Store.Post().GetPostsCreatedAt(directChannel.Id, *data.DirectPost.CreateAt)
|
||||
require.Nil(t, err)
|
||||
posts, nErr := th.App.Srv().Store.Post().GetPostsCreatedAt(directChannel.Id, *data.DirectPost.CreateAt)
|
||||
require.Nil(t, nErr)
|
||||
require.Len(t, posts, 1)
|
||||
|
||||
post := posts[0]
|
||||
@@ -3278,8 +3278,8 @@ func TestImportImportDirectPost(t *testing.T) {
|
||||
require.Equal(t, 0, errLine)
|
||||
AssertAllPostsCount(t, th.App, initialPostCount, 4, "")
|
||||
|
||||
posts, err := th.App.Srv().Store.Post().GetPostsCreatedAt(directChannel.Id, *data.DirectPost.CreateAt)
|
||||
require.Nil(t, err)
|
||||
posts, nErr := th.App.Srv().Store.Post().GetPostsCreatedAt(directChannel.Id, *data.DirectPost.CreateAt)
|
||||
require.Nil(t, nErr)
|
||||
require.Len(t, posts, 1)
|
||||
|
||||
post := posts[0]
|
||||
@@ -3314,8 +3314,8 @@ func TestImportImportDirectPost(t *testing.T) {
|
||||
require.Equal(t, 0, errLine)
|
||||
|
||||
// Check the post values.
|
||||
posts, err := th.App.Srv().Store.Post().GetPostsCreatedAt(directChannel.Id, *data.DirectPost.CreateAt)
|
||||
require.Nil(t, err)
|
||||
posts, nErr := th.App.Srv().Store.Post().GetPostsCreatedAt(directChannel.Id, *data.DirectPost.CreateAt)
|
||||
require.Nil(t, nErr)
|
||||
require.Len(t, posts, 1)
|
||||
|
||||
post := posts[0]
|
||||
@@ -3349,8 +3349,8 @@ func TestImportImportDirectPost(t *testing.T) {
|
||||
groupChannel = channel
|
||||
|
||||
// Get the number of posts in the system.
|
||||
result, appErr = th.App.Srv().Store.Post().AnalyticsPostCount("", false, false)
|
||||
require.Nil(t, appErr)
|
||||
result, nErr := th.App.Srv().Store.Post().AnalyticsPostCount("", false, false)
|
||||
require.Nil(t, nErr)
|
||||
initialPostCount = result
|
||||
|
||||
t.Run("Try adding an invalid post in dry run mode", func(t *testing.T) {
|
||||
@@ -3441,8 +3441,8 @@ func TestImportImportDirectPost(t *testing.T) {
|
||||
AssertAllPostsCount(t, th.App, initialPostCount, 1, "")
|
||||
|
||||
// Check the post values.
|
||||
posts, err := th.App.Srv().Store.Post().GetPostsCreatedAt(groupChannel.Id, *data.DirectPost.CreateAt)
|
||||
require.Nil(t, err)
|
||||
posts, nErr := th.App.Srv().Store.Post().GetPostsCreatedAt(groupChannel.Id, *data.DirectPost.CreateAt)
|
||||
require.Nil(t, nErr)
|
||||
require.Len(t, posts, 1)
|
||||
|
||||
post := posts[0]
|
||||
@@ -3473,8 +3473,8 @@ func TestImportImportDirectPost(t *testing.T) {
|
||||
AssertAllPostsCount(t, th.App, initialPostCount, 1, "")
|
||||
|
||||
// Check the post values.
|
||||
posts, err := th.App.Srv().Store.Post().GetPostsCreatedAt(groupChannel.Id, *data.DirectPost.CreateAt)
|
||||
require.Nil(t, err)
|
||||
posts, nErr := th.App.Srv().Store.Post().GetPostsCreatedAt(groupChannel.Id, *data.DirectPost.CreateAt)
|
||||
require.Nil(t, nErr)
|
||||
require.Len(t, posts, 1)
|
||||
|
||||
post := posts[0]
|
||||
@@ -3548,8 +3548,8 @@ func TestImportImportDirectPost(t *testing.T) {
|
||||
require.Equal(t, 0, errLine)
|
||||
AssertAllPostsCount(t, th.App, initialPostCount, 4, "")
|
||||
|
||||
posts, err := th.App.Srv().Store.Post().GetPostsCreatedAt(groupChannel.Id, *data.DirectPost.CreateAt)
|
||||
require.Nil(t, err)
|
||||
posts, nErr := th.App.Srv().Store.Post().GetPostsCreatedAt(groupChannel.Id, *data.DirectPost.CreateAt)
|
||||
require.Nil(t, nErr)
|
||||
require.Len(t, posts, 1)
|
||||
|
||||
post := posts[0]
|
||||
@@ -3587,8 +3587,8 @@ func TestImportImportDirectPost(t *testing.T) {
|
||||
AssertAllPostsCount(t, th.App, initialPostCount, 5, "")
|
||||
|
||||
// Check the post values.
|
||||
posts, err := th.App.Srv().Store.Post().GetPostsCreatedAt(groupChannel.Id, *data.DirectPost.CreateAt)
|
||||
require.Nil(t, err)
|
||||
posts, nErr := th.App.Srv().Store.Post().GetPostsCreatedAt(groupChannel.Id, *data.DirectPost.CreateAt)
|
||||
require.Nil(t, nErr)
|
||||
require.Len(t, posts, 1)
|
||||
|
||||
post := posts[0]
|
||||
@@ -3626,8 +3626,8 @@ func TestImportImportDirectPost(t *testing.T) {
|
||||
AssertAllPostsCount(t, th.App, initialPostCount, 6, "")
|
||||
|
||||
// Check the post values.
|
||||
posts, err := th.App.Srv().Store.Post().GetPostsCreatedAt(groupChannel.Id, *data.DirectPost.CreateAt)
|
||||
require.Nil(t, err)
|
||||
posts, nErr := th.App.Srv().Store.Post().GetPostsCreatedAt(groupChannel.Id, *data.DirectPost.CreateAt)
|
||||
require.Nil(t, nErr)
|
||||
|
||||
require.Len(t, posts, 1, "Unexpected number of posts found.")
|
||||
|
||||
@@ -3671,8 +3671,8 @@ func TestImportImportDirectPost(t *testing.T) {
|
||||
AssertAllPostsCount(t, th.App, initialPostCount, 8, "")
|
||||
|
||||
// Check the post values.
|
||||
posts, err := th.App.Srv().Store.Post().GetPostsCreatedAt(groupChannel.Id, *data.DirectPost.CreateAt)
|
||||
require.Nil(t, err)
|
||||
posts, nErr := th.App.Srv().Store.Post().GetPostsCreatedAt(groupChannel.Id, *data.DirectPost.CreateAt)
|
||||
require.Nil(t, nErr)
|
||||
|
||||
require.Len(t, posts, 1, "Unexpected number of posts found.")
|
||||
|
||||
@@ -3681,8 +3681,8 @@ func TestImportImportDirectPost(t *testing.T) {
|
||||
require.False(t, postBool, "Post properties not as expected")
|
||||
|
||||
// Check the reply values.
|
||||
replies, err := th.App.Srv().Store.Post().GetPostsCreatedAt(channel.Id, *replyTime)
|
||||
require.Nil(t, err)
|
||||
replies, nErr := th.App.Srv().Store.Post().GetPostsCreatedAt(channel.Id, *replyTime)
|
||||
require.Nil(t, nErr)
|
||||
|
||||
require.Len(t, replies, 1, "Unexpected number of posts found.")
|
||||
|
||||
|
||||
47
app/post.go
47
app/post.go
@@ -365,7 +365,7 @@ func (a *App) attachFilesToPost(post *model.Post) *model.AppError {
|
||||
post.FileIds = attachedIds
|
||||
|
||||
if _, err := a.Srv().Store.Post().Overwrite(post); err != nil {
|
||||
return err
|
||||
return model.NewAppError("attachFilesToPost", "app.post.overwrite.app_error", nil, err.Error(), http.StatusInternalServerError)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -669,11 +669,33 @@ func (a *App) PatchPost(postId string, patch *model.PostPatch) (*model.Post, *mo
|
||||
}
|
||||
|
||||
func (a *App) GetPostsPage(options model.GetPostsOptions) (*model.PostList, *model.AppError) {
|
||||
return a.Srv().Store.Post().GetPosts(options, false)
|
||||
postList, err := a.Srv().Store.Post().GetPosts(options, false)
|
||||
if err != nil {
|
||||
var invErr *store.ErrInvalidInput
|
||||
switch {
|
||||
case errors.As(err, &invErr):
|
||||
return nil, model.NewAppError("GetPostsPage", "app.post.get_posts.app_error", nil, invErr.Error(), http.StatusBadRequest)
|
||||
default:
|
||||
return nil, model.NewAppError("GetPostsPage", "app.post.get_root_posts.app_error", nil, err.Error(), http.StatusInternalServerError)
|
||||
}
|
||||
}
|
||||
|
||||
return postList, nil
|
||||
}
|
||||
|
||||
func (a *App) GetPosts(channelId string, offset int, limit int) (*model.PostList, *model.AppError) {
|
||||
return a.Srv().Store.Post().GetPosts(model.GetPostsOptions{ChannelId: channelId, Page: offset, PerPage: limit}, true)
|
||||
postList, err := a.Srv().Store.Post().GetPosts(model.GetPostsOptions{ChannelId: channelId, Page: offset, PerPage: limit}, true)
|
||||
if err != nil {
|
||||
var invErr *store.ErrInvalidInput
|
||||
switch {
|
||||
case errors.As(err, &invErr):
|
||||
return nil, model.NewAppError("GetPosts", "app.post.get_posts.app_error", nil, invErr.Error(), http.StatusBadRequest)
|
||||
default:
|
||||
return nil, model.NewAppError("GetPosts", "app.post.get_root_posts.app_error", nil, err.Error(), http.StatusInternalServerError)
|
||||
}
|
||||
}
|
||||
|
||||
return postList, nil
|
||||
}
|
||||
|
||||
func (a *App) GetPostsEtag(channelId string) string {
|
||||
@@ -1085,7 +1107,7 @@ func (a *App) searchPostsInTeam(teamId string, userId string, paramsList []*mode
|
||||
go func(params *model.SearchParams) {
|
||||
defer wg.Done()
|
||||
postList, err := a.Srv().Store.Post().Search(teamId, userId, params)
|
||||
pchan <- store.StoreResult{Data: postList, Err: err}
|
||||
pchan <- store.StoreResult{Data: postList, NErr: err}
|
||||
}(params)
|
||||
}
|
||||
|
||||
@@ -1095,8 +1117,8 @@ func (a *App) searchPostsInTeam(teamId string, userId string, paramsList []*mode
|
||||
posts := model.NewPostList()
|
||||
|
||||
for result := range pchan {
|
||||
if result.Err != nil {
|
||||
return nil, result.Err
|
||||
if result.NErr != nil {
|
||||
return nil, model.NewAppError("searchPostsInTeam", "app.post.search.app_error", nil, result.NErr.Error(), http.StatusInternalServerError)
|
||||
}
|
||||
data := result.Data.(*model.PostList)
|
||||
posts.Extend(data)
|
||||
@@ -1140,7 +1162,6 @@ func (a *App) SearchPostsInTeam(teamId string, paramsList []*model.SearchParams)
|
||||
|
||||
func (a *App) SearchPostsInTeamForUser(terms string, userId string, teamId string, isOrSearch bool, includeDeletedChannels bool, timeZoneOffset int, page, perPage int) (*model.PostSearchResults, *model.AppError) {
|
||||
var postSearchResults *model.PostSearchResults
|
||||
var err *model.AppError
|
||||
paramsList := model.ParseSearchParams(strings.TrimSpace(terms), timeZoneOffset)
|
||||
includeDeleted := includeDeletedChannels && *a.Config().TeamSettings.ExperimentalViewArchivedChannels
|
||||
|
||||
@@ -1172,9 +1193,15 @@ func (a *App) SearchPostsInTeamForUser(terms string, userId string, teamId strin
|
||||
return model.MakePostSearchResults(model.NewPostList(), nil), nil
|
||||
}
|
||||
|
||||
postSearchResults, err = a.Srv().Store.Post().SearchPostsInTeamForUser(finalParamsList, userId, teamId, page, perPage)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
postSearchResults, nErr := a.Srv().Store.Post().SearchPostsInTeamForUser(finalParamsList, userId, teamId, page, perPage)
|
||||
if nErr != nil {
|
||||
var appErr *model.AppError
|
||||
switch {
|
||||
case errors.As(nErr, &appErr):
|
||||
return nil, appErr
|
||||
default:
|
||||
return nil, model.NewAppError("SearchPostsInTeamForUser", "app.post.search.app_error", nil, nErr.Error(), http.StatusInternalServerError)
|
||||
}
|
||||
}
|
||||
|
||||
return postSearchResults, nil
|
||||
|
||||
@@ -4,20 +4,21 @@
|
||||
package app
|
||||
|
||||
import (
|
||||
"github.com/mattermost/mattermost-server/v5/store"
|
||||
"net/http"
|
||||
"reflect"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/mattermost/mattermost-server/v5/store"
|
||||
|
||||
"github.com/Masterminds/semver/v3"
|
||||
"github.com/mattermost/mattermost-server/v5/config"
|
||||
"github.com/mattermost/mattermost-server/v5/mlog"
|
||||
"github.com/mattermost/mattermost-server/v5/model"
|
||||
"github.com/mattermost/mattermost-server/v5/utils"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/reflog/dateconstraints"
|
||||
date_constraints "github.com/reflog/dateconstraints"
|
||||
)
|
||||
|
||||
const MAX_REPEAT_VIEWINGS = 3
|
||||
@@ -274,9 +275,9 @@ func (a *App) UpdateProductNotices() *model.AppError {
|
||||
}
|
||||
mlog.Debug("Will fetch notices from", mlog.String("url", NOTICES_JSON_URL), mlog.Bool("skip_cache", skip))
|
||||
var appErr *model.AppError
|
||||
cachedPostCount, appErr = a.Srv().Store.Post().AnalyticsPostCount("", false, false)
|
||||
if appErr != nil {
|
||||
mlog.Error("Failed to fetch post count", mlog.String("error", appErr.Error()))
|
||||
cachedPostCount, err = a.Srv().Store.Post().AnalyticsPostCount("", false, false)
|
||||
if err != nil {
|
||||
mlog.Error("Failed to fetch post count", mlog.String("error", err.Error()))
|
||||
}
|
||||
|
||||
cachedUserCount, appErr = a.Srv().Store.User().Count(model.UserCountOptions{IncludeDeleted: true})
|
||||
|
||||
Ссылка в новой задаче
Block a user