PLT-7 adding loc db calls for posts table

Этот коммит содержится в:
=Corey Hulen
2016-01-20 10:34:31 -06:00
родитель 3ac5ecf0e9
Коммит aac8d121a0
10 изменённых файлов: 182 добавлений и 181 удалений

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

@@ -159,7 +159,7 @@ func getAnalytics(c *Context, w http.ResponseWriter, r *http.Request) {
rows[2] = &model.AnalyticsRow{"post_count", 0} rows[2] = &model.AnalyticsRow{"post_count", 0}
openChan := Srv.Store.Channel().AnalyticsTypeCount(c.T, teamId, model.CHANNEL_OPEN) openChan := Srv.Store.Channel().AnalyticsTypeCount(c.T, teamId, model.CHANNEL_OPEN)
privateChan := Srv.Store.Channel().AnalyticsTypeCount(c.T, teamId, model.CHANNEL_PRIVATE) privateChan := Srv.Store.Channel().AnalyticsTypeCount(c.T, teamId, model.CHANNEL_PRIVATE)
postChan := Srv.Store.Post().AnalyticsPostCount(teamId) postChan := Srv.Store.Post().AnalyticsPostCount(c.T, teamId)
if r := <-openChan; r.Err != nil { if r := <-openChan; r.Err != nil {
c.Err = r.Err c.Err = r.Err
@@ -184,14 +184,14 @@ func getAnalytics(c *Context, w http.ResponseWriter, r *http.Request) {
w.Write([]byte(rows.ToJson())) w.Write([]byte(rows.ToJson()))
} else if name == "post_counts_day" { } else if name == "post_counts_day" {
if r := <-Srv.Store.Post().AnalyticsPostCountsByDay(teamId); r.Err != nil { if r := <-Srv.Store.Post().AnalyticsPostCountsByDay(c.T, teamId); r.Err != nil {
c.Err = r.Err c.Err = r.Err
return return
} else { } else {
w.Write([]byte(r.Data.(model.AnalyticsRows).ToJson())) w.Write([]byte(r.Data.(model.AnalyticsRows).ToJson()))
} }
} else if name == "user_counts_with_posts_day" { } else if name == "user_counts_with_posts_day" {
if r := <-Srv.Store.Post().AnalyticsUserCountsWithPostsByDay(teamId); r.Err != nil { if r := <-Srv.Store.Post().AnalyticsUserCountsWithPostsByDay(c.T, teamId); r.Err != nil {
c.Err = r.Err c.Err = r.Err
return return
} else { } else {

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

@@ -192,7 +192,7 @@ func ExportChannels(T goi18n.TranslateFunc, writer ExportWriter, options *Export
} }
for _, channel := range channels { for _, channel := range channels {
if err := ExportPosts(writer, options, channel.Id); err != nil { if err := ExportPosts(T, writer, options, channel.Id); err != nil {
return err return err
} }
} }
@@ -200,10 +200,10 @@ func ExportChannels(T goi18n.TranslateFunc, writer ExportWriter, options *Export
return nil return nil
} }
func ExportPosts(writer ExportWriter, options *ExportOptions, channelId string) *model.AppError { func ExportPosts(T goi18n.TranslateFunc, writer ExportWriter, options *ExportOptions, channelId string) *model.AppError {
// Get the posts // Get the posts
var posts []*model.Post var posts []*model.Post
if result := <-Srv.Store.Post().GetForExport(channelId); result.Err != nil { if result := <-Srv.Store.Post().GetForExport(T, channelId); result.Err != nil {
return result.Err return result.Err
} else { } else {
posts = result.Data.([]*model.Post) posts = result.Data.([]*model.Post)

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

@@ -14,10 +14,10 @@ import (
// some of the usual checks. (IsValid is still run) // some of the usual checks. (IsValid is still run)
// //
func ImportPost(post *model.Post) { func ImportPost(T goi18n.TranslateFunc, post *model.Post) {
post.Hashtags, _ = model.ParseHashtags(post.Message) post.Hashtags, _ = model.ParseHashtags(post.Message)
if result := <-Srv.Store.Post().Save(post); result.Err != nil { if result := <-Srv.Store.Post().Save(T, post); result.Err != nil {
l4g.Debug("Error saving post. user=" + post.UserId + ", message=" + post.Message) l4g.Debug("Error saving post. user=" + post.UserId + ", message=" + post.Message)
} }
} }

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

@@ -72,7 +72,7 @@ func createPost(c *Context, w http.ResponseWriter, r *http.Request) {
func CreatePost(c *Context, post *model.Post, triggerWebhooks bool) (*model.Post, *model.AppError) { func CreatePost(c *Context, post *model.Post, triggerWebhooks bool) (*model.Post, *model.AppError) {
var pchan store.StoreChannel var pchan store.StoreChannel
if len(post.RootId) > 0 { if len(post.RootId) > 0 {
pchan = Srv.Store.Post().Get(post.RootId) pchan = Srv.Store.Post().Get(c.T, post.RootId)
} }
// Verify the parent/child relationships are correct // Verify the parent/child relationships are correct
@@ -138,7 +138,7 @@ func CreatePost(c *Context, post *model.Post, triggerWebhooks bool) (*model.Post
} }
var rpost *model.Post var rpost *model.Post
if result := <-Srv.Store.Post().Save(post); result.Err != nil { if result := <-Srv.Store.Post().Save(c.T, post); result.Err != nil {
return nil, result.Err return nil, result.Err
} else { } else {
rpost = result.Data.(*model.Post) rpost = result.Data.(*model.Post)
@@ -711,7 +711,7 @@ func updatePost(c *Context, w http.ResponseWriter, r *http.Request) {
} }
cchan := Srv.Store.Channel().CheckPermissionsTo(c.T, c.Session.TeamId, post.ChannelId, c.Session.UserId) cchan := Srv.Store.Channel().CheckPermissionsTo(c.T, c.Session.TeamId, post.ChannelId, c.Session.UserId)
pchan := Srv.Store.Post().Get(post.Id) pchan := Srv.Store.Post().Get(c.T, post.Id)
if !c.HasPermissionsToChannel(cchan, "updatePost") { if !c.HasPermissionsToChannel(cchan, "updatePost") {
return return
@@ -745,7 +745,7 @@ func updatePost(c *Context, w http.ResponseWriter, r *http.Request) {
hashtags, _ := model.ParseHashtags(post.Message) hashtags, _ := model.ParseHashtags(post.Message)
if result := <-Srv.Store.Post().Update(oldPost, post.Message, hashtags); result.Err != nil { if result := <-Srv.Store.Post().Update(c.T, oldPost, post.Message, hashtags); result.Err != nil {
c.Err = result.Err c.Err = result.Err
return return
} else { } else {
@@ -782,7 +782,7 @@ func getPosts(c *Context, w http.ResponseWriter, r *http.Request) {
} }
cchan := Srv.Store.Channel().CheckPermissionsTo(c.T, c.Session.TeamId, id, c.Session.UserId) cchan := Srv.Store.Channel().CheckPermissionsTo(c.T, c.Session.TeamId, id, c.Session.UserId)
etagChan := Srv.Store.Post().GetEtag(id) etagChan := Srv.Store.Post().GetEtag(c.T, id)
if !c.HasPermissionsToChannel(cchan, "getPosts") { if !c.HasPermissionsToChannel(cchan, "getPosts") {
return return
@@ -794,7 +794,7 @@ func getPosts(c *Context, w http.ResponseWriter, r *http.Request) {
return return
} }
pchan := Srv.Store.Post().GetPosts(id, offset, limit) pchan := Srv.Store.Post().GetPosts(c.T, id, offset, limit)
if result := <-pchan; result.Err != nil { if result := <-pchan; result.Err != nil {
c.Err = result.Err c.Err = result.Err
@@ -824,7 +824,7 @@ func getPostsSince(c *Context, w http.ResponseWriter, r *http.Request) {
} }
cchan := Srv.Store.Channel().CheckPermissionsTo(c.T, c.Session.TeamId, id, c.Session.UserId) cchan := Srv.Store.Channel().CheckPermissionsTo(c.T, c.Session.TeamId, id, c.Session.UserId)
pchan := Srv.Store.Post().GetPostsSince(id, time) pchan := Srv.Store.Post().GetPostsSince(c.T, id, time)
if !c.HasPermissionsToChannel(cchan, "getPostsSince") { if !c.HasPermissionsToChannel(cchan, "getPostsSince") {
return return
@@ -857,7 +857,7 @@ func getPost(c *Context, w http.ResponseWriter, r *http.Request) {
} }
cchan := Srv.Store.Channel().CheckPermissionsTo(c.T, c.Session.TeamId, channelId, c.Session.UserId) cchan := Srv.Store.Channel().CheckPermissionsTo(c.T, c.Session.TeamId, channelId, c.Session.UserId)
pchan := Srv.Store.Post().Get(postId) pchan := Srv.Store.Post().Get(c.T, postId)
if !c.HasPermissionsToChannel(cchan, "getPost") { if !c.HasPermissionsToChannel(cchan, "getPost") {
return return
@@ -891,7 +891,7 @@ func getPostById(c *Context, w http.ResponseWriter, r *http.Request) {
return return
} }
if result := <-Srv.Store.Post().Get(postId); result.Err != nil { if result := <-Srv.Store.Post().Get(c.T, postId); result.Err != nil {
c.Err = result.Err c.Err = result.Err
return return
} else { } else {
@@ -933,7 +933,7 @@ func deletePost(c *Context, w http.ResponseWriter, r *http.Request) {
} }
cchan := Srv.Store.Channel().CheckPermissionsTo(c.T, c.Session.TeamId, channelId, c.Session.UserId) cchan := Srv.Store.Channel().CheckPermissionsTo(c.T, c.Session.TeamId, channelId, c.Session.UserId)
pchan := Srv.Store.Post().Get(postId) pchan := Srv.Store.Post().Get(c.T, postId)
if result := <-pchan; result.Err != nil { if result := <-pchan; result.Err != nil {
c.Err = result.Err c.Err = result.Err
@@ -963,7 +963,7 @@ func deletePost(c *Context, w http.ResponseWriter, r *http.Request) {
return return
} }
if dresult := <-Srv.Store.Post().Delete(postId, model.GetMillis()); dresult.Err != nil { if dresult := <-Srv.Store.Post().Delete(c.T, postId, model.GetMillis()); dresult.Err != nil {
c.Err = dresult.Err c.Err = dresult.Err
return return
} }
@@ -1014,7 +1014,7 @@ func getPostsBeforeOrAfter(c *Context, w http.ResponseWriter, r *http.Request, b
cchan := Srv.Store.Channel().CheckPermissionsTo(c.T, c.Session.TeamId, id, c.Session.UserId) cchan := Srv.Store.Channel().CheckPermissionsTo(c.T, c.Session.TeamId, id, c.Session.UserId)
// We can do better than this etag in this situation // We can do better than this etag in this situation
etagChan := Srv.Store.Post().GetEtag(id) etagChan := Srv.Store.Post().GetEtag(c.T, id)
if !c.HasPermissionsToChannel(cchan, "getPostsBeforeOrAfter") { if !c.HasPermissionsToChannel(cchan, "getPostsBeforeOrAfter") {
return return
@@ -1027,9 +1027,9 @@ func getPostsBeforeOrAfter(c *Context, w http.ResponseWriter, r *http.Request, b
var pchan store.StoreChannel var pchan store.StoreChannel
if before { if before {
pchan = Srv.Store.Post().GetPostsBefore(id, postId, numPosts, offset) pchan = Srv.Store.Post().GetPostsBefore(c.T, id, postId, numPosts, offset)
} else { } else {
pchan = Srv.Store.Post().GetPostsAfter(id, postId, numPosts, offset) pchan = Srv.Store.Post().GetPostsAfter(c.T, id, postId, numPosts, offset)
} }
if result := <-pchan; result.Err != nil { if result := <-pchan; result.Err != nil {
@@ -1057,7 +1057,7 @@ func searchPosts(c *Context, w http.ResponseWriter, r *http.Request) {
for _, params := range paramsList { for _, params := range paramsList {
// don't allow users to search for everything // don't allow users to search for everything
if params.Terms != "*" { if params.Terms != "*" {
channels = append(channels, Srv.Store.Post().Search(c.Session.TeamId, c.Session.UserId, params)) channels = append(channels, Srv.Store.Post().Search(c.T, c.Session.TeamId, c.Session.UserId, params))
} }
} }

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

@@ -129,7 +129,7 @@ func SlackAddUsers(T goi18n.TranslateFunc, teamId string, slackusers []SlackUser
return addedUsers return addedUsers
} }
func SlackAddPosts(channel *model.Channel, posts []SlackPost, users map[string]*model.User) { func SlackAddPosts(T goi18n.TranslateFunc, channel *model.Channel, posts []SlackPost, users map[string]*model.User) {
for _, sPost := range posts { for _, sPost := range posts {
switch { switch {
case sPost.Type == "message" && (sPost.SubType == "" || sPost.SubType == "file_share"): case sPost.Type == "message" && (sPost.SubType == "" || sPost.SubType == "file_share"):
@@ -146,7 +146,7 @@ func SlackAddPosts(channel *model.Channel, posts []SlackPost, users map[string]*
Message: sPost.Text, Message: sPost.Text,
CreateAt: SlackConvertTimeStamp(sPost.TimeStamp), CreateAt: SlackConvertTimeStamp(sPost.TimeStamp),
} }
ImportPost(&newPost) ImportPost(T, &newPost)
case sPost.Type == "message" && sPost.SubType == "file_comment": case sPost.Type == "message" && sPost.SubType == "file_comment":
if sPost.Comment["user"] == "" { if sPost.Comment["user"] == "" {
l4g.Debug("Message without user") l4g.Debug("Message without user")
@@ -161,7 +161,7 @@ func SlackAddPosts(channel *model.Channel, posts []SlackPost, users map[string]*
Message: sPost.Comment["comment"], Message: sPost.Comment["comment"],
CreateAt: SlackConvertTimeStamp(sPost.TimeStamp), CreateAt: SlackConvertTimeStamp(sPost.TimeStamp),
} }
ImportPost(&newPost) ImportPost(T, &newPost)
case sPost.Type == "message" && sPost.SubType == "bot_message": case sPost.Type == "message" && sPost.SubType == "bot_message":
// In the future this will use the "Action Post" spec to post // In the future this will use the "Action Post" spec to post
// a message without using a username. For now we just warn that we don't handle this case // a message without using a username. For now we just warn that we don't handle this case
@@ -200,7 +200,7 @@ func SlackAddChannels(T goi18n.TranslateFunc, teamId string, slackchannels []Sla
} }
log.WriteString(newChannel.DisplayName + "\r\n") log.WriteString(newChannel.DisplayName + "\r\n")
addedChannels[sChannel.Id] = mChannel addedChannels[sChannel.Id] = mChannel
SlackAddPosts(mChannel, posts[sChannel.Name], users) SlackAddPosts(T, mChannel, posts[sChannel.Name], users)
} }
return addedChannels return addedChannels

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

@@ -1460,7 +1460,7 @@ func PermanentDeleteUser(c *Context, user *model.User) *model.AppError {
return result.Err return result.Err
} }
if result := <-Srv.Store.Post().PermanentDeleteByUser(user.Id); result.Err != nil { if result := <-Srv.Store.Post().PermanentDeleteByUser(c.T, user.Id); result.Err != nil {
return result.Err return result.Err
} }

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

@@ -11,6 +11,7 @@ import (
"github.com/mattermost/platform/model" "github.com/mattermost/platform/model"
"github.com/mattermost/platform/utils" "github.com/mattermost/platform/utils"
goi18n "github.com/nicksnyder/go-i18n/i18n"
) )
type SqlPostStore struct { type SqlPostStore struct {
@@ -50,7 +51,7 @@ func (s SqlPostStore) CreateIndexesIfNotExists() {
s.CreateFullTextIndexIfNotExists("idx_posts_hashtags_txt", "Posts", "Hashtags") s.CreateFullTextIndexIfNotExists("idx_posts_hashtags_txt", "Posts", "Hashtags")
} }
func (s SqlPostStore) Save(post *model.Post) StoreChannel { func (s SqlPostStore) Save(T goi18n.TranslateFunc, post *model.Post) StoreChannel {
storeChannel := make(StoreChannel) storeChannel := make(StoreChannel)
go func() { go func() {
@@ -97,7 +98,7 @@ func (s SqlPostStore) Save(post *model.Post) StoreChannel {
return storeChannel return storeChannel
} }
func (s SqlPostStore) Update(oldPost *model.Post, newMessage string, newHashtags string) StoreChannel { func (s SqlPostStore) Update(T goi18n.TranslateFunc, oldPost *model.Post, newMessage string, newHashtags string) StoreChannel {
storeChannel := make(StoreChannel) storeChannel := make(StoreChannel)
go func() { go func() {
@@ -142,7 +143,7 @@ func (s SqlPostStore) Update(oldPost *model.Post, newMessage string, newHashtags
return storeChannel return storeChannel
} }
func (s SqlPostStore) Get(id string) StoreChannel { func (s SqlPostStore) Get(T goi18n.TranslateFunc, id string) StoreChannel {
storeChannel := make(StoreChannel) storeChannel := make(StoreChannel)
go func() { go func() {
@@ -188,7 +189,7 @@ type etagPosts struct {
UpdateAt int64 UpdateAt int64
} }
func (s SqlPostStore) GetEtag(channelId string) StoreChannel { func (s SqlPostStore) GetEtag(T goi18n.TranslateFunc, channelId string) StoreChannel {
storeChannel := make(StoreChannel) storeChannel := make(StoreChannel)
go func() { go func() {
@@ -209,7 +210,7 @@ func (s SqlPostStore) GetEtag(channelId string) StoreChannel {
return storeChannel return storeChannel
} }
func (s SqlPostStore) Delete(postId string, time int64) StoreChannel { func (s SqlPostStore) Delete(T goi18n.TranslateFunc, postId string, time int64) StoreChannel {
storeChannel := make(StoreChannel) storeChannel := make(StoreChannel)
go func() { go func() {
@@ -227,7 +228,7 @@ func (s SqlPostStore) Delete(postId string, time int64) StoreChannel {
return storeChannel return storeChannel
} }
func (s SqlPostStore) permanentDelete(postId string) StoreChannel { func (s SqlPostStore) permanentDelete(T goi18n.TranslateFunc, postId string) StoreChannel {
storeChannel := make(StoreChannel) storeChannel := make(StoreChannel)
go func() { go func() {
@@ -245,7 +246,7 @@ func (s SqlPostStore) permanentDelete(postId string) StoreChannel {
return storeChannel return storeChannel
} }
func (s SqlPostStore) permanentDeleteAllCommentByUser(userId string) StoreChannel { func (s SqlPostStore) permanentDeleteAllCommentByUser(T goi18n.TranslateFunc, userId string) StoreChannel {
storeChannel := make(StoreChannel) storeChannel := make(StoreChannel)
go func() { go func() {
@@ -263,14 +264,14 @@ func (s SqlPostStore) permanentDeleteAllCommentByUser(userId string) StoreChanne
return storeChannel return storeChannel
} }
func (s SqlPostStore) PermanentDeleteByUser(userId string) StoreChannel { func (s SqlPostStore) PermanentDeleteByUser(T goi18n.TranslateFunc, userId string) StoreChannel {
storeChannel := make(StoreChannel) storeChannel := make(StoreChannel)
go func() { go func() {
result := StoreResult{} result := StoreResult{}
// First attempt to delete all the comments for a user // First attempt to delete all the comments for a user
if r := <-s.permanentDeleteAllCommentByUser(userId); r.Err != nil { if r := <-s.permanentDeleteAllCommentByUser(T, userId); r.Err != nil {
result.Err = r.Err result.Err = r.Err
storeChannel <- result storeChannel <- result
close(storeChannel) close(storeChannel)
@@ -294,7 +295,7 @@ func (s SqlPostStore) PermanentDeleteByUser(userId string) StoreChannel {
found = false found = false
for _, id := range ids { for _, id := range ids {
found = true found = true
if r := <-s.permanentDelete(id); r.Err != nil { if r := <-s.permanentDelete(T, id); r.Err != nil {
result.Err = r.Err result.Err = r.Err
storeChannel <- result storeChannel <- result
close(storeChannel) close(storeChannel)
@@ -320,7 +321,7 @@ func (s SqlPostStore) PermanentDeleteByUser(userId string) StoreChannel {
return storeChannel return storeChannel
} }
func (s SqlPostStore) GetPosts(channelId string, offset int, limit int) StoreChannel { func (s SqlPostStore) GetPosts(T goi18n.TranslateFunc, channelId string, offset int, limit int) StoreChannel {
storeChannel := make(StoreChannel) storeChannel := make(StoreChannel)
go func() { go func() {
@@ -333,8 +334,8 @@ func (s SqlPostStore) GetPosts(channelId string, offset int, limit int) StoreCha
return return
} }
rpc := s.getRootPosts(channelId, offset, limit) rpc := s.getRootPosts(T, channelId, offset, limit)
cpc := s.getParentsPosts(channelId, offset, limit) cpc := s.getParentsPosts(T, channelId, offset, limit)
if rpr := <-rpc; rpr.Err != nil { if rpr := <-rpc; rpr.Err != nil {
result.Err = rpr.Err result.Err = rpr.Err
@@ -367,7 +368,7 @@ func (s SqlPostStore) GetPosts(channelId string, offset int, limit int) StoreCha
return storeChannel return storeChannel
} }
func (s SqlPostStore) GetPostsSince(channelId string, time int64) StoreChannel { func (s SqlPostStore) GetPostsSince(T goi18n.TranslateFunc, channelId string, time int64) StoreChannel {
storeChannel := make(StoreChannel) storeChannel := make(StoreChannel)
go func() { go func() {
@@ -425,15 +426,15 @@ func (s SqlPostStore) GetPostsSince(channelId string, time int64) StoreChannel {
return storeChannel return storeChannel
} }
func (s SqlPostStore) GetPostsBefore(channelId string, postId string, numPosts int, offset int) StoreChannel { func (s SqlPostStore) GetPostsBefore(T goi18n.TranslateFunc, channelId string, postId string, numPosts int, offset int) StoreChannel {
return s.getPostsAround(channelId, postId, numPosts, offset, true) return s.getPostsAround(T, channelId, postId, numPosts, offset, true)
} }
func (s SqlPostStore) GetPostsAfter(channelId string, postId string, numPosts int, offset int) StoreChannel { func (s SqlPostStore) GetPostsAfter(T goi18n.TranslateFunc, channelId string, postId string, numPosts int, offset int) StoreChannel {
return s.getPostsAround(channelId, postId, numPosts, offset, false) return s.getPostsAround(T, channelId, postId, numPosts, offset, false)
} }
func (s SqlPostStore) getPostsAround(channelId string, postId string, numPosts int, offset int, before bool) StoreChannel { func (s SqlPostStore) getPostsAround(T goi18n.TranslateFunc, channelId string, postId string, numPosts int, offset int, before bool) StoreChannel {
storeChannel := make(StoreChannel) storeChannel := make(StoreChannel)
go func() { go func() {
@@ -523,7 +524,7 @@ func (s SqlPostStore) getPostsAround(channelId string, postId string, numPosts i
return storeChannel return storeChannel
} }
func (s SqlPostStore) getRootPosts(channelId string, offset int, limit int) StoreChannel { func (s SqlPostStore) getRootPosts(T goi18n.TranslateFunc, channelId string, offset int, limit int) StoreChannel {
storeChannel := make(StoreChannel) storeChannel := make(StoreChannel)
go func() { go func() {
@@ -544,7 +545,7 @@ func (s SqlPostStore) getRootPosts(channelId string, offset int, limit int) Stor
return storeChannel return storeChannel
} }
func (s SqlPostStore) getParentsPosts(channelId string, offset int, limit int) StoreChannel { func (s SqlPostStore) getParentsPosts(T goi18n.TranslateFunc, channelId string, offset int, limit int) StoreChannel {
storeChannel := make(StoreChannel) storeChannel := make(StoreChannel)
go func() { go func() {
@@ -600,7 +601,7 @@ var specialSearchChar = []string{
"@", "@",
} }
func (s SqlPostStore) Search(teamId string, userId string, params *model.SearchParams) StoreChannel { func (s SqlPostStore) Search(T goi18n.TranslateFunc, teamId string, userId string, params *model.SearchParams) StoreChannel {
storeChannel := make(StoreChannel) storeChannel := make(StoreChannel)
go func() { go func() {
@@ -765,7 +766,7 @@ func (s SqlPostStore) Search(teamId string, userId string, params *model.SearchP
return storeChannel return storeChannel
} }
func (s SqlPostStore) GetForExport(channelId string) StoreChannel { func (s SqlPostStore) GetForExport(T goi18n.TranslateFunc, channelId string) StoreChannel {
storeChannel := make(StoreChannel) storeChannel := make(StoreChannel)
go func() { go func() {
@@ -789,7 +790,7 @@ func (s SqlPostStore) GetForExport(channelId string) StoreChannel {
return storeChannel return storeChannel
} }
func (s SqlPostStore) AnalyticsUserCountsWithPostsByDay(teamId string) StoreChannel { func (s SqlPostStore) AnalyticsUserCountsWithPostsByDay(T goi18n.TranslateFunc, teamId string) StoreChannel {
storeChannel := make(StoreChannel) storeChannel := make(StoreChannel)
go func() { go func() {
@@ -853,7 +854,7 @@ func (s SqlPostStore) AnalyticsUserCountsWithPostsByDay(teamId string) StoreChan
return storeChannel return storeChannel
} }
func (s SqlPostStore) AnalyticsPostCountsByDay(teamId string) StoreChannel { func (s SqlPostStore) AnalyticsPostCountsByDay(T goi18n.TranslateFunc, teamId string) StoreChannel {
storeChannel := make(StoreChannel) storeChannel := make(StoreChannel)
go func() { go func() {
@@ -918,7 +919,7 @@ func (s SqlPostStore) AnalyticsPostCountsByDay(teamId string) StoreChannel {
return storeChannel return storeChannel
} }
func (s SqlPostStore) AnalyticsPostCount(teamId string) StoreChannel { func (s SqlPostStore) AnalyticsPostCount(T goi18n.TranslateFunc, teamId string) StoreChannel {
storeChannel := make(StoreChannel) storeChannel := make(StoreChannel)
go func() { go func() {

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

@@ -20,11 +20,11 @@ func TestPostStoreSave(t *testing.T) {
o1.UserId = model.NewId() o1.UserId = model.NewId()
o1.Message = "a" + model.NewId() + "b" o1.Message = "a" + model.NewId() + "b"
if err := (<-store.Post().Save(&o1)).Err; err != nil { if err := (<-store.Post().Save(utils.T, &o1)).Err; err != nil {
t.Fatal("couldn't save item", err) t.Fatal("couldn't save item", err)
} }
if err := (<-store.Post().Save(&o1)).Err; err == nil { if err := (<-store.Post().Save(utils.T, &o1)).Err; err == nil {
t.Fatal("shouldn't be able to update from save") t.Fatal("shouldn't be able to update from save")
} }
} }
@@ -37,19 +37,19 @@ func TestPostStoreGet(t *testing.T) {
o1.UserId = model.NewId() o1.UserId = model.NewId()
o1.Message = "a" + model.NewId() + "b" o1.Message = "a" + model.NewId() + "b"
etag1 := (<-store.Post().GetEtag(o1.ChannelId)).Data.(string) etag1 := (<-store.Post().GetEtag(utils.T, o1.ChannelId)).Data.(string)
if strings.Index(etag1, model.CurrentVersion+".0.") != 0 { if strings.Index(etag1, model.CurrentVersion+".0.") != 0 {
t.Fatal("Invalid Etag") t.Fatal("Invalid Etag")
} }
o1 = (<-store.Post().Save(o1)).Data.(*model.Post) o1 = (<-store.Post().Save(utils.T, o1)).Data.(*model.Post)
etag2 := (<-store.Post().GetEtag(o1.ChannelId)).Data.(string) etag2 := (<-store.Post().GetEtag(utils.T, o1.ChannelId)).Data.(string)
if strings.Index(etag2, model.CurrentVersion+"."+o1.Id) != 0 { if strings.Index(etag2, model.CurrentVersion+"."+o1.Id) != 0 {
t.Fatal("Invalid Etag") t.Fatal("Invalid Etag")
} }
if r1 := <-store.Post().Get(o1.Id); r1.Err != nil { if r1 := <-store.Post().Get(utils.T, o1.Id); r1.Err != nil {
t.Fatal(r1.Err) t.Fatal(r1.Err)
} else { } else {
if r1.Data.(*model.PostList).Posts[o1.Id].CreateAt != o1.CreateAt { if r1.Data.(*model.PostList).Posts[o1.Id].CreateAt != o1.CreateAt {
@@ -57,7 +57,7 @@ func TestPostStoreGet(t *testing.T) {
} }
} }
if err := (<-store.Post().Get("123")).Err; err == nil { if err := (<-store.Post().Get(utils.T, "123")).Err; err == nil {
t.Fatal("Missing id should have failed") t.Fatal("Missing id should have failed")
} }
} }
@@ -69,7 +69,7 @@ func TestPostStoreUpdate(t *testing.T) {
o1.ChannelId = model.NewId() o1.ChannelId = model.NewId()
o1.UserId = model.NewId() o1.UserId = model.NewId()
o1.Message = "a" + model.NewId() + "AAAAAAAAAAA" o1.Message = "a" + model.NewId() + "AAAAAAAAAAA"
o1 = (<-store.Post().Save(o1)).Data.(*model.Post) o1 = (<-store.Post().Save(utils.T, o1)).Data.(*model.Post)
o2 := &model.Post{} o2 := &model.Post{}
o2.ChannelId = o1.ChannelId o2.ChannelId = o1.ChannelId
@@ -77,50 +77,50 @@ func TestPostStoreUpdate(t *testing.T) {
o2.Message = "a" + model.NewId() + "CCCCCCCCC" o2.Message = "a" + model.NewId() + "CCCCCCCCC"
o2.ParentId = o1.Id o2.ParentId = o1.Id
o2.RootId = o1.Id o2.RootId = o1.Id
o2 = (<-store.Post().Save(o2)).Data.(*model.Post) o2 = (<-store.Post().Save(utils.T, o2)).Data.(*model.Post)
o3 := &model.Post{} o3 := &model.Post{}
o3.ChannelId = o1.ChannelId o3.ChannelId = o1.ChannelId
o3.UserId = model.NewId() o3.UserId = model.NewId()
o3.Message = "a" + model.NewId() + "QQQQQQQQQQ" o3.Message = "a" + model.NewId() + "QQQQQQQQQQ"
o3 = (<-store.Post().Save(o3)).Data.(*model.Post) o3 = (<-store.Post().Save(utils.T, o3)).Data.(*model.Post)
ro1 := (<-store.Post().Get(o1.Id)).Data.(*model.PostList).Posts[o1.Id] ro1 := (<-store.Post().Get(utils.T, o1.Id)).Data.(*model.PostList).Posts[o1.Id]
ro2 := (<-store.Post().Get(o1.Id)).Data.(*model.PostList).Posts[o2.Id] ro2 := (<-store.Post().Get(utils.T, o1.Id)).Data.(*model.PostList).Posts[o2.Id]
ro6 := (<-store.Post().Get(o3.Id)).Data.(*model.PostList).Posts[o3.Id] ro6 := (<-store.Post().Get(utils.T, o3.Id)).Data.(*model.PostList).Posts[o3.Id]
if ro1.Message != o1.Message { if ro1.Message != o1.Message {
t.Fatal("Failed to save/get") t.Fatal("Failed to save/get")
} }
msg := o1.Message + "BBBBBBBBBB" msg := o1.Message + "BBBBBBBBBB"
if result := <-store.Post().Update(ro1, msg, ""); result.Err != nil { if result := <-store.Post().Update(utils.T, ro1, msg, ""); result.Err != nil {
t.Fatal(result.Err) t.Fatal(result.Err)
} }
msg2 := o2.Message + "DDDDDDD" msg2 := o2.Message + "DDDDDDD"
if result := <-store.Post().Update(ro2, msg2, ""); result.Err != nil { if result := <-store.Post().Update(utils.T, ro2, msg2, ""); result.Err != nil {
t.Fatal(result.Err) t.Fatal(result.Err)
} }
msg3 := o3.Message + "WWWWWWW" msg3 := o3.Message + "WWWWWWW"
if result := <-store.Post().Update(ro6, msg3, "#hashtag"); result.Err != nil { if result := <-store.Post().Update(utils.T, ro6, msg3, "#hashtag"); result.Err != nil {
t.Fatal(result.Err) t.Fatal(result.Err)
} }
ro3 := (<-store.Post().Get(o1.Id)).Data.(*model.PostList).Posts[o1.Id] ro3 := (<-store.Post().Get(utils.T, o1.Id)).Data.(*model.PostList).Posts[o1.Id]
if ro3.Message != msg { if ro3.Message != msg {
t.Fatal("Failed to update/get") t.Fatal("Failed to update/get")
} }
ro4 := (<-store.Post().Get(o1.Id)).Data.(*model.PostList).Posts[o2.Id] ro4 := (<-store.Post().Get(utils.T, o1.Id)).Data.(*model.PostList).Posts[o2.Id]
if ro4.Message != msg2 { if ro4.Message != msg2 {
t.Fatal("Failed to update/get") t.Fatal("Failed to update/get")
} }
ro5 := (<-store.Post().Get(o3.Id)).Data.(*model.PostList).Posts[o3.Id] ro5 := (<-store.Post().Get(utils.T, o3.Id)).Data.(*model.PostList).Posts[o3.Id]
if ro5.Message != msg3 && ro5.Hashtags != "#hashtag" { if ro5.Message != msg3 && ro5.Hashtags != "#hashtag" {
t.Fatal("Failed to update/get") t.Fatal("Failed to update/get")
@@ -136,14 +136,14 @@ func TestPostStoreDelete(t *testing.T) {
o1.UserId = model.NewId() o1.UserId = model.NewId()
o1.Message = "a" + model.NewId() + "b" o1.Message = "a" + model.NewId() + "b"
etag1 := (<-store.Post().GetEtag(o1.ChannelId)).Data.(string) etag1 := (<-store.Post().GetEtag(utils.T, o1.ChannelId)).Data.(string)
if strings.Index(etag1, model.CurrentVersion+".0.") != 0 { if strings.Index(etag1, model.CurrentVersion+".0.") != 0 {
t.Fatal("Invalid Etag") t.Fatal("Invalid Etag")
} }
o1 = (<-store.Post().Save(o1)).Data.(*model.Post) o1 = (<-store.Post().Save(utils.T, o1)).Data.(*model.Post)
if r1 := <-store.Post().Get(o1.Id); r1.Err != nil { if r1 := <-store.Post().Get(utils.T, o1.Id); r1.Err != nil {
t.Fatal(r1.Err) t.Fatal(r1.Err)
} else { } else {
if r1.Data.(*model.PostList).Posts[o1.Id].CreateAt != o1.CreateAt { if r1.Data.(*model.PostList).Posts[o1.Id].CreateAt != o1.CreateAt {
@@ -151,16 +151,16 @@ func TestPostStoreDelete(t *testing.T) {
} }
} }
if r2 := <-store.Post().Delete(o1.Id, model.GetMillis()); r2.Err != nil { if r2 := <-store.Post().Delete(utils.T, o1.Id, model.GetMillis()); r2.Err != nil {
t.Fatal(r2.Err) t.Fatal(r2.Err)
} }
if r3 := (<-store.Post().Get(o1.Id)); r3.Err == nil { if r3 := (<-store.Post().Get(utils.T, o1.Id)); r3.Err == nil {
t.Log(r3.Data) t.Log(r3.Data)
t.Fatal("Missing id should have failed") t.Fatal("Missing id should have failed")
} }
etag2 := (<-store.Post().GetEtag(o1.ChannelId)).Data.(string) etag2 := (<-store.Post().GetEtag(utils.T, o1.ChannelId)).Data.(string)
if strings.Index(etag2, model.CurrentVersion+"."+o1.Id) != 0 { if strings.Index(etag2, model.CurrentVersion+"."+o1.Id) != 0 {
t.Fatal("Invalid Etag") t.Fatal("Invalid Etag")
} }
@@ -173,7 +173,7 @@ func TestPostStoreDelete1Level(t *testing.T) {
o1.ChannelId = model.NewId() o1.ChannelId = model.NewId()
o1.UserId = model.NewId() o1.UserId = model.NewId()
o1.Message = "a" + model.NewId() + "b" o1.Message = "a" + model.NewId() + "b"
o1 = (<-store.Post().Save(o1)).Data.(*model.Post) o1 = (<-store.Post().Save(utils.T, o1)).Data.(*model.Post)
o2 := &model.Post{} o2 := &model.Post{}
o2.ChannelId = o1.ChannelId o2.ChannelId = o1.ChannelId
@@ -181,17 +181,17 @@ func TestPostStoreDelete1Level(t *testing.T) {
o2.Message = "a" + model.NewId() + "b" o2.Message = "a" + model.NewId() + "b"
o2.ParentId = o1.Id o2.ParentId = o1.Id
o2.RootId = o1.Id o2.RootId = o1.Id
o2 = (<-store.Post().Save(o2)).Data.(*model.Post) o2 = (<-store.Post().Save(utils.T, o2)).Data.(*model.Post)
if r2 := <-store.Post().Delete(o1.Id, model.GetMillis()); r2.Err != nil { if r2 := <-store.Post().Delete(utils.T, o1.Id, model.GetMillis()); r2.Err != nil {
t.Fatal(r2.Err) t.Fatal(r2.Err)
} }
if r3 := (<-store.Post().Get(o1.Id)); r3.Err == nil { if r3 := (<-store.Post().Get(utils.T, o1.Id)); r3.Err == nil {
t.Fatal("Deleted id should have failed") t.Fatal("Deleted id should have failed")
} }
if r4 := (<-store.Post().Get(o2.Id)); r4.Err == nil { if r4 := (<-store.Post().Get(utils.T, o2.Id)); r4.Err == nil {
t.Fatal("Deleted id should have failed") t.Fatal("Deleted id should have failed")
} }
} }
@@ -203,7 +203,7 @@ func TestPostStoreDelete2Level(t *testing.T) {
o1.ChannelId = model.NewId() o1.ChannelId = model.NewId()
o1.UserId = model.NewId() o1.UserId = model.NewId()
o1.Message = "a" + model.NewId() + "b" o1.Message = "a" + model.NewId() + "b"
o1 = (<-store.Post().Save(o1)).Data.(*model.Post) o1 = (<-store.Post().Save(utils.T, o1)).Data.(*model.Post)
o2 := &model.Post{} o2 := &model.Post{}
o2.ChannelId = o1.ChannelId o2.ChannelId = o1.ChannelId
@@ -211,7 +211,7 @@ func TestPostStoreDelete2Level(t *testing.T) {
o2.Message = "a" + model.NewId() + "b" o2.Message = "a" + model.NewId() + "b"
o2.ParentId = o1.Id o2.ParentId = o1.Id
o2.RootId = o1.Id o2.RootId = o1.Id
o2 = (<-store.Post().Save(o2)).Data.(*model.Post) o2 = (<-store.Post().Save(utils.T, o2)).Data.(*model.Post)
o3 := &model.Post{} o3 := &model.Post{}
o3.ChannelId = o1.ChannelId o3.ChannelId = o1.ChannelId
@@ -219,31 +219,31 @@ func TestPostStoreDelete2Level(t *testing.T) {
o3.Message = "a" + model.NewId() + "b" o3.Message = "a" + model.NewId() + "b"
o3.ParentId = o2.Id o3.ParentId = o2.Id
o3.RootId = o1.Id o3.RootId = o1.Id
o3 = (<-store.Post().Save(o3)).Data.(*model.Post) o3 = (<-store.Post().Save(utils.T, o3)).Data.(*model.Post)
o4 := &model.Post{} o4 := &model.Post{}
o4.ChannelId = model.NewId() o4.ChannelId = model.NewId()
o4.UserId = model.NewId() o4.UserId = model.NewId()
o4.Message = "a" + model.NewId() + "b" o4.Message = "a" + model.NewId() + "b"
o4 = (<-store.Post().Save(o4)).Data.(*model.Post) o4 = (<-store.Post().Save(utils.T, o4)).Data.(*model.Post)
if r2 := <-store.Post().Delete(o1.Id, model.GetMillis()); r2.Err != nil { if r2 := <-store.Post().Delete(utils.T, o1.Id, model.GetMillis()); r2.Err != nil {
t.Fatal(r2.Err) t.Fatal(r2.Err)
} }
if r3 := (<-store.Post().Get(o1.Id)); r3.Err == nil { if r3 := (<-store.Post().Get(utils.T, o1.Id)); r3.Err == nil {
t.Fatal("Deleted id should have failed") t.Fatal("Deleted id should have failed")
} }
if r4 := (<-store.Post().Get(o2.Id)); r4.Err == nil { if r4 := (<-store.Post().Get(utils.T, o2.Id)); r4.Err == nil {
t.Fatal("Deleted id should have failed") t.Fatal("Deleted id should have failed")
} }
if r5 := (<-store.Post().Get(o3.Id)); r5.Err == nil { if r5 := (<-store.Post().Get(utils.T, o3.Id)); r5.Err == nil {
t.Fatal("Deleted id should have failed") t.Fatal("Deleted id should have failed")
} }
if r6 := <-store.Post().Get(o4.Id); r6.Err != nil { if r6 := <-store.Post().Get(utils.T, o4.Id); r6.Err != nil {
t.Fatal(r6.Err) t.Fatal(r6.Err)
} }
} }
@@ -255,7 +255,7 @@ func TestPostStorePermDelete1Level(t *testing.T) {
o1.ChannelId = model.NewId() o1.ChannelId = model.NewId()
o1.UserId = model.NewId() o1.UserId = model.NewId()
o1.Message = "a" + model.NewId() + "b" o1.Message = "a" + model.NewId() + "b"
o1 = (<-store.Post().Save(o1)).Data.(*model.Post) o1 = (<-store.Post().Save(utils.T, o1)).Data.(*model.Post)
o2 := &model.Post{} o2 := &model.Post{}
o2.ChannelId = o1.ChannelId o2.ChannelId = o1.ChannelId
@@ -263,17 +263,17 @@ func TestPostStorePermDelete1Level(t *testing.T) {
o2.Message = "a" + model.NewId() + "b" o2.Message = "a" + model.NewId() + "b"
o2.ParentId = o1.Id o2.ParentId = o1.Id
o2.RootId = o1.Id o2.RootId = o1.Id
o2 = (<-store.Post().Save(o2)).Data.(*model.Post) o2 = (<-store.Post().Save(utils.T, o2)).Data.(*model.Post)
if r2 := <-store.Post().PermanentDeleteByUser(o2.UserId); r2.Err != nil { if r2 := <-store.Post().PermanentDeleteByUser(utils.T, o2.UserId); r2.Err != nil {
t.Fatal(r2.Err) t.Fatal(r2.Err)
} }
if r3 := (<-store.Post().Get(o1.Id)); r3.Err != nil { if r3 := (<-store.Post().Get(utils.T, o1.Id)); r3.Err != nil {
t.Fatal("Deleted id shouldn't have failed") t.Fatal("Deleted id shouldn't have failed")
} }
if r4 := (<-store.Post().Get(o2.Id)); r4.Err == nil { if r4 := (<-store.Post().Get(utils.T, o2.Id)); r4.Err == nil {
t.Fatal("Deleted id should have failed") t.Fatal("Deleted id should have failed")
} }
} }
@@ -285,7 +285,7 @@ func TestPostStorePermDelete1Level2(t *testing.T) {
o1.ChannelId = model.NewId() o1.ChannelId = model.NewId()
o1.UserId = model.NewId() o1.UserId = model.NewId()
o1.Message = "a" + model.NewId() + "b" o1.Message = "a" + model.NewId() + "b"
o1 = (<-store.Post().Save(o1)).Data.(*model.Post) o1 = (<-store.Post().Save(utils.T, o1)).Data.(*model.Post)
o2 := &model.Post{} o2 := &model.Post{}
o2.ChannelId = o1.ChannelId o2.ChannelId = o1.ChannelId
@@ -293,27 +293,27 @@ func TestPostStorePermDelete1Level2(t *testing.T) {
o2.Message = "a" + model.NewId() + "b" o2.Message = "a" + model.NewId() + "b"
o2.ParentId = o1.Id o2.ParentId = o1.Id
o2.RootId = o1.Id o2.RootId = o1.Id
o2 = (<-store.Post().Save(o2)).Data.(*model.Post) o2 = (<-store.Post().Save(utils.T, o2)).Data.(*model.Post)
o3 := &model.Post{} o3 := &model.Post{}
o3.ChannelId = model.NewId() o3.ChannelId = model.NewId()
o3.UserId = model.NewId() o3.UserId = model.NewId()
o3.Message = "a" + model.NewId() + "b" o3.Message = "a" + model.NewId() + "b"
o3 = (<-store.Post().Save(o3)).Data.(*model.Post) o3 = (<-store.Post().Save(utils.T, o3)).Data.(*model.Post)
if r2 := <-store.Post().PermanentDeleteByUser(o1.UserId); r2.Err != nil { if r2 := <-store.Post().PermanentDeleteByUser(utils.T, o1.UserId); r2.Err != nil {
t.Fatal(r2.Err) t.Fatal(r2.Err)
} }
if r3 := (<-store.Post().Get(o1.Id)); r3.Err == nil { if r3 := (<-store.Post().Get(utils.T, o1.Id)); r3.Err == nil {
t.Fatal("Deleted id should have failed") t.Fatal("Deleted id should have failed")
} }
if r4 := (<-store.Post().Get(o2.Id)); r4.Err == nil { if r4 := (<-store.Post().Get(utils.T, o2.Id)); r4.Err == nil {
t.Fatal("Deleted id should have failed") t.Fatal("Deleted id should have failed")
} }
if r5 := (<-store.Post().Get(o3.Id)); r5.Err != nil { if r5 := (<-store.Post().Get(utils.T, o3.Id)); r5.Err != nil {
t.Fatal("Deleted id shouldn't have failed") t.Fatal("Deleted id shouldn't have failed")
} }
} }
@@ -325,7 +325,7 @@ func TestPostStoreGetWithChildren(t *testing.T) {
o1.ChannelId = model.NewId() o1.ChannelId = model.NewId()
o1.UserId = model.NewId() o1.UserId = model.NewId()
o1.Message = "a" + model.NewId() + "b" o1.Message = "a" + model.NewId() + "b"
o1 = (<-store.Post().Save(o1)).Data.(*model.Post) o1 = (<-store.Post().Save(utils.T, o1)).Data.(*model.Post)
o2 := &model.Post{} o2 := &model.Post{}
o2.ChannelId = o1.ChannelId o2.ChannelId = o1.ChannelId
@@ -333,7 +333,7 @@ func TestPostStoreGetWithChildren(t *testing.T) {
o2.Message = "a" + model.NewId() + "b" o2.Message = "a" + model.NewId() + "b"
o2.ParentId = o1.Id o2.ParentId = o1.Id
o2.RootId = o1.Id o2.RootId = o1.Id
o2 = (<-store.Post().Save(o2)).Data.(*model.Post) o2 = (<-store.Post().Save(utils.T, o2)).Data.(*model.Post)
o3 := &model.Post{} o3 := &model.Post{}
o3.ChannelId = o1.ChannelId o3.ChannelId = o1.ChannelId
@@ -341,9 +341,9 @@ func TestPostStoreGetWithChildren(t *testing.T) {
o3.Message = "a" + model.NewId() + "b" o3.Message = "a" + model.NewId() + "b"
o3.ParentId = o2.Id o3.ParentId = o2.Id
o3.RootId = o1.Id o3.RootId = o1.Id
o3 = (<-store.Post().Save(o3)).Data.(*model.Post) o3 = (<-store.Post().Save(utils.T, o3)).Data.(*model.Post)
if r1 := <-store.Post().Get(o1.Id); r1.Err != nil { if r1 := <-store.Post().Get(utils.T, o1.Id); r1.Err != nil {
t.Fatal(r1.Err) t.Fatal(r1.Err)
} else { } else {
pl := r1.Data.(*model.PostList) pl := r1.Data.(*model.PostList)
@@ -352,9 +352,9 @@ func TestPostStoreGetWithChildren(t *testing.T) {
} }
} }
Must(store.Post().Delete(o3.Id, model.GetMillis())) Must(store.Post().Delete(utils.T, o3.Id, model.GetMillis()))
if r2 := <-store.Post().Get(o1.Id); r2.Err != nil { if r2 := <-store.Post().Get(utils.T, o1.Id); r2.Err != nil {
t.Fatal(r2.Err) t.Fatal(r2.Err)
} else { } else {
pl := r2.Data.(*model.PostList) pl := r2.Data.(*model.PostList)
@@ -363,9 +363,9 @@ func TestPostStoreGetWithChildren(t *testing.T) {
} }
} }
Must(store.Post().Delete(o2.Id, model.GetMillis())) Must(store.Post().Delete(utils.T, o2.Id, model.GetMillis()))
if r3 := <-store.Post().Get(o1.Id); r3.Err != nil { if r3 := <-store.Post().Get(utils.T, o1.Id); r3.Err != nil {
t.Fatal(r3.Err) t.Fatal(r3.Err)
} else { } else {
pl := r3.Data.(*model.PostList) pl := r3.Data.(*model.PostList)
@@ -382,7 +382,7 @@ func TestPostStoreGetPostsWtihDetails(t *testing.T) {
o1.ChannelId = model.NewId() o1.ChannelId = model.NewId()
o1.UserId = model.NewId() o1.UserId = model.NewId()
o1.Message = "a" + model.NewId() + "b" o1.Message = "a" + model.NewId() + "b"
o1 = (<-store.Post().Save(o1)).Data.(*model.Post) o1 = (<-store.Post().Save(utils.T, o1)).Data.(*model.Post)
time.Sleep(2 * time.Millisecond) time.Sleep(2 * time.Millisecond)
o2 := &model.Post{} o2 := &model.Post{}
@@ -391,7 +391,7 @@ func TestPostStoreGetPostsWtihDetails(t *testing.T) {
o2.Message = "a" + model.NewId() + "b" o2.Message = "a" + model.NewId() + "b"
o2.ParentId = o1.Id o2.ParentId = o1.Id
o2.RootId = o1.Id o2.RootId = o1.Id
o2 = (<-store.Post().Save(o2)).Data.(*model.Post) o2 = (<-store.Post().Save(utils.T, o2)).Data.(*model.Post)
time.Sleep(2 * time.Millisecond) time.Sleep(2 * time.Millisecond)
o2a := &model.Post{} o2a := &model.Post{}
@@ -400,7 +400,7 @@ func TestPostStoreGetPostsWtihDetails(t *testing.T) {
o2a.Message = "a" + model.NewId() + "b" o2a.Message = "a" + model.NewId() + "b"
o2a.ParentId = o1.Id o2a.ParentId = o1.Id
o2a.RootId = o1.Id o2a.RootId = o1.Id
o2a = (<-store.Post().Save(o2a)).Data.(*model.Post) o2a = (<-store.Post().Save(utils.T, o2a)).Data.(*model.Post)
time.Sleep(2 * time.Millisecond) time.Sleep(2 * time.Millisecond)
o3 := &model.Post{} o3 := &model.Post{}
@@ -409,14 +409,14 @@ func TestPostStoreGetPostsWtihDetails(t *testing.T) {
o3.Message = "a" + model.NewId() + "b" o3.Message = "a" + model.NewId() + "b"
o3.ParentId = o1.Id o3.ParentId = o1.Id
o3.RootId = o1.Id o3.RootId = o1.Id
o3 = (<-store.Post().Save(o3)).Data.(*model.Post) o3 = (<-store.Post().Save(utils.T, o3)).Data.(*model.Post)
time.Sleep(2 * time.Millisecond) time.Sleep(2 * time.Millisecond)
o4 := &model.Post{} o4 := &model.Post{}
o4.ChannelId = o1.ChannelId o4.ChannelId = o1.ChannelId
o4.UserId = model.NewId() o4.UserId = model.NewId()
o4.Message = "a" + model.NewId() + "b" o4.Message = "a" + model.NewId() + "b"
o4 = (<-store.Post().Save(o4)).Data.(*model.Post) o4 = (<-store.Post().Save(utils.T, o4)).Data.(*model.Post)
time.Sleep(2 * time.Millisecond) time.Sleep(2 * time.Millisecond)
o5 := &model.Post{} o5 := &model.Post{}
@@ -425,9 +425,9 @@ func TestPostStoreGetPostsWtihDetails(t *testing.T) {
o5.Message = "a" + model.NewId() + "b" o5.Message = "a" + model.NewId() + "b"
o5.ParentId = o4.Id o5.ParentId = o4.Id
o5.RootId = o4.Id o5.RootId = o4.Id
o5 = (<-store.Post().Save(o5)).Data.(*model.Post) o5 = (<-store.Post().Save(utils.T, o5)).Data.(*model.Post)
r1 := (<-store.Post().GetPosts(o1.ChannelId, 0, 4)).Data.(*model.PostList) r1 := (<-store.Post().GetPosts(utils.T, o1.ChannelId, 0, 4)).Data.(*model.PostList)
if r1.Order[0] != o5.Id { if r1.Order[0] != o5.Id {
t.Fatal("invalid order") t.Fatal("invalid order")
@@ -460,14 +460,14 @@ func TestPostStoreGetPostsBeforeAfter(t *testing.T) {
o0.ChannelId = model.NewId() o0.ChannelId = model.NewId()
o0.UserId = model.NewId() o0.UserId = model.NewId()
o0.Message = "a" + model.NewId() + "b" o0.Message = "a" + model.NewId() + "b"
o0 = (<-store.Post().Save(o0)).Data.(*model.Post) o0 = (<-store.Post().Save(utils.T, o0)).Data.(*model.Post)
time.Sleep(2 * time.Millisecond) time.Sleep(2 * time.Millisecond)
o1 := &model.Post{} o1 := &model.Post{}
o1.ChannelId = model.NewId() o1.ChannelId = model.NewId()
o1.UserId = model.NewId() o1.UserId = model.NewId()
o1.Message = "a" + model.NewId() + "b" o1.Message = "a" + model.NewId() + "b"
o1 = (<-store.Post().Save(o1)).Data.(*model.Post) o1 = (<-store.Post().Save(utils.T, o1)).Data.(*model.Post)
time.Sleep(2 * time.Millisecond) time.Sleep(2 * time.Millisecond)
o2 := &model.Post{} o2 := &model.Post{}
@@ -476,7 +476,7 @@ func TestPostStoreGetPostsBeforeAfter(t *testing.T) {
o2.Message = "a" + model.NewId() + "b" o2.Message = "a" + model.NewId() + "b"
o2.ParentId = o1.Id o2.ParentId = o1.Id
o2.RootId = o1.Id o2.RootId = o1.Id
o2 = (<-store.Post().Save(o2)).Data.(*model.Post) o2 = (<-store.Post().Save(utils.T, o2)).Data.(*model.Post)
time.Sleep(2 * time.Millisecond) time.Sleep(2 * time.Millisecond)
o2a := &model.Post{} o2a := &model.Post{}
@@ -485,7 +485,7 @@ func TestPostStoreGetPostsBeforeAfter(t *testing.T) {
o2a.Message = "a" + model.NewId() + "b" o2a.Message = "a" + model.NewId() + "b"
o2a.ParentId = o1.Id o2a.ParentId = o1.Id
o2a.RootId = o1.Id o2a.RootId = o1.Id
o2a = (<-store.Post().Save(o2a)).Data.(*model.Post) o2a = (<-store.Post().Save(utils.T, o2a)).Data.(*model.Post)
time.Sleep(2 * time.Millisecond) time.Sleep(2 * time.Millisecond)
o3 := &model.Post{} o3 := &model.Post{}
@@ -494,14 +494,14 @@ func TestPostStoreGetPostsBeforeAfter(t *testing.T) {
o3.Message = "a" + model.NewId() + "b" o3.Message = "a" + model.NewId() + "b"
o3.ParentId = o1.Id o3.ParentId = o1.Id
o3.RootId = o1.Id o3.RootId = o1.Id
o3 = (<-store.Post().Save(o3)).Data.(*model.Post) o3 = (<-store.Post().Save(utils.T, o3)).Data.(*model.Post)
time.Sleep(2 * time.Millisecond) time.Sleep(2 * time.Millisecond)
o4 := &model.Post{} o4 := &model.Post{}
o4.ChannelId = o1.ChannelId o4.ChannelId = o1.ChannelId
o4.UserId = model.NewId() o4.UserId = model.NewId()
o4.Message = "a" + model.NewId() + "b" o4.Message = "a" + model.NewId() + "b"
o4 = (<-store.Post().Save(o4)).Data.(*model.Post) o4 = (<-store.Post().Save(utils.T, o4)).Data.(*model.Post)
time.Sleep(2 * time.Millisecond) time.Sleep(2 * time.Millisecond)
o5 := &model.Post{} o5 := &model.Post{}
@@ -510,15 +510,15 @@ func TestPostStoreGetPostsBeforeAfter(t *testing.T) {
o5.Message = "a" + model.NewId() + "b" o5.Message = "a" + model.NewId() + "b"
o5.ParentId = o4.Id o5.ParentId = o4.Id
o5.RootId = o4.Id o5.RootId = o4.Id
o5 = (<-store.Post().Save(o5)).Data.(*model.Post) o5 = (<-store.Post().Save(utils.T, o5)).Data.(*model.Post)
r1 := (<-store.Post().GetPostsBefore(o1.ChannelId, o1.Id, 4, 0)).Data.(*model.PostList) r1 := (<-store.Post().GetPostsBefore(utils.T, o1.ChannelId, o1.Id, 4, 0)).Data.(*model.PostList)
if len(r1.Posts) != 0 { if len(r1.Posts) != 0 {
t.Fatal("Wrong size") t.Fatal("Wrong size")
} }
r2 := (<-store.Post().GetPostsAfter(o1.ChannelId, o1.Id, 4, 0)).Data.(*model.PostList) r2 := (<-store.Post().GetPostsAfter(utils.T, o1.ChannelId, o1.Id, 4, 0)).Data.(*model.PostList)
if r2.Order[0] != o4.Id { if r2.Order[0] != o4.Id {
t.Fatal("invalid order") t.Fatal("invalid order")
@@ -540,7 +540,7 @@ func TestPostStoreGetPostsBeforeAfter(t *testing.T) {
t.Fatal("wrong size") t.Fatal("wrong size")
} }
r3 := (<-store.Post().GetPostsBefore(o3.ChannelId, o3.Id, 2, 0)).Data.(*model.PostList) r3 := (<-store.Post().GetPostsBefore(utils.T, o3.ChannelId, o3.Id, 2, 0)).Data.(*model.PostList)
if r3.Order[0] != o2a.Id { if r3.Order[0] != o2a.Id {
t.Fatal("invalid order") t.Fatal("invalid order")
@@ -565,14 +565,14 @@ func TestPostStoreGetPostsSince(t *testing.T) {
o0.ChannelId = model.NewId() o0.ChannelId = model.NewId()
o0.UserId = model.NewId() o0.UserId = model.NewId()
o0.Message = "a" + model.NewId() + "b" o0.Message = "a" + model.NewId() + "b"
o0 = (<-store.Post().Save(o0)).Data.(*model.Post) o0 = (<-store.Post().Save(utils.T, o0)).Data.(*model.Post)
time.Sleep(2 * time.Millisecond) time.Sleep(2 * time.Millisecond)
o1 := &model.Post{} o1 := &model.Post{}
o1.ChannelId = model.NewId() o1.ChannelId = model.NewId()
o1.UserId = model.NewId() o1.UserId = model.NewId()
o1.Message = "a" + model.NewId() + "b" o1.Message = "a" + model.NewId() + "b"
o1 = (<-store.Post().Save(o1)).Data.(*model.Post) o1 = (<-store.Post().Save(utils.T, o1)).Data.(*model.Post)
time.Sleep(2 * time.Millisecond) time.Sleep(2 * time.Millisecond)
o2 := &model.Post{} o2 := &model.Post{}
@@ -581,7 +581,7 @@ func TestPostStoreGetPostsSince(t *testing.T) {
o2.Message = "a" + model.NewId() + "b" o2.Message = "a" + model.NewId() + "b"
o2.ParentId = o1.Id o2.ParentId = o1.Id
o2.RootId = o1.Id o2.RootId = o1.Id
o2 = (<-store.Post().Save(o2)).Data.(*model.Post) o2 = (<-store.Post().Save(utils.T, o2)).Data.(*model.Post)
time.Sleep(2 * time.Millisecond) time.Sleep(2 * time.Millisecond)
o2a := &model.Post{} o2a := &model.Post{}
@@ -590,7 +590,7 @@ func TestPostStoreGetPostsSince(t *testing.T) {
o2a.Message = "a" + model.NewId() + "b" o2a.Message = "a" + model.NewId() + "b"
o2a.ParentId = o1.Id o2a.ParentId = o1.Id
o2a.RootId = o1.Id o2a.RootId = o1.Id
o2a = (<-store.Post().Save(o2a)).Data.(*model.Post) o2a = (<-store.Post().Save(utils.T, o2a)).Data.(*model.Post)
time.Sleep(2 * time.Millisecond) time.Sleep(2 * time.Millisecond)
o3 := &model.Post{} o3 := &model.Post{}
@@ -599,14 +599,14 @@ func TestPostStoreGetPostsSince(t *testing.T) {
o3.Message = "a" + model.NewId() + "b" o3.Message = "a" + model.NewId() + "b"
o3.ParentId = o1.Id o3.ParentId = o1.Id
o3.RootId = o1.Id o3.RootId = o1.Id
o3 = (<-store.Post().Save(o3)).Data.(*model.Post) o3 = (<-store.Post().Save(utils.T, o3)).Data.(*model.Post)
time.Sleep(2 * time.Millisecond) time.Sleep(2 * time.Millisecond)
o4 := &model.Post{} o4 := &model.Post{}
o4.ChannelId = o1.ChannelId o4.ChannelId = o1.ChannelId
o4.UserId = model.NewId() o4.UserId = model.NewId()
o4.Message = "a" + model.NewId() + "b" o4.Message = "a" + model.NewId() + "b"
o4 = (<-store.Post().Save(o4)).Data.(*model.Post) o4 = (<-store.Post().Save(utils.T, o4)).Data.(*model.Post)
time.Sleep(2 * time.Millisecond) time.Sleep(2 * time.Millisecond)
o5 := &model.Post{} o5 := &model.Post{}
@@ -615,9 +615,9 @@ func TestPostStoreGetPostsSince(t *testing.T) {
o5.Message = "a" + model.NewId() + "b" o5.Message = "a" + model.NewId() + "b"
o5.ParentId = o4.Id o5.ParentId = o4.Id
o5.RootId = o4.Id o5.RootId = o4.Id
o5 = (<-store.Post().Save(o5)).Data.(*model.Post) o5 = (<-store.Post().Save(utils.T, o5)).Data.(*model.Post)
r1 := (<-store.Post().GetPostsSince(o1.ChannelId, o1.CreateAt)).Data.(*model.PostList) r1 := (<-store.Post().GetPostsSince(utils.T, o1.ChannelId, o1.CreateAt)).Data.(*model.PostList)
if r1.Order[0] != o5.Id { if r1.Order[0] != o5.Id {
t.Fatal("invalid order") t.Fatal("invalid order")
@@ -674,84 +674,84 @@ func TestPostStoreSearch(t *testing.T) {
o1.ChannelId = c1.Id o1.ChannelId = c1.Id
o1.UserId = model.NewId() o1.UserId = model.NewId()
o1.Message = "corey mattermost new york" o1.Message = "corey mattermost new york"
o1 = (<-store.Post().Save(o1)).Data.(*model.Post) o1 = (<-store.Post().Save(utils.T, o1)).Data.(*model.Post)
o2 := &model.Post{} o2 := &model.Post{}
o2.ChannelId = c1.Id o2.ChannelId = c1.Id
o2.UserId = model.NewId() o2.UserId = model.NewId()
o2.Message = "New Jersey is where John is from" o2.Message = "New Jersey is where John is from"
o2 = (<-store.Post().Save(o2)).Data.(*model.Post) o2 = (<-store.Post().Save(utils.T, o2)).Data.(*model.Post)
o3 := &model.Post{} o3 := &model.Post{}
o3.ChannelId = c2.Id o3.ChannelId = c2.Id
o3.UserId = model.NewId() o3.UserId = model.NewId()
o3.Message = "New Jersey is where John is from corey new york" o3.Message = "New Jersey is where John is from corey new york"
o3 = (<-store.Post().Save(o3)).Data.(*model.Post) o3 = (<-store.Post().Save(utils.T, o3)).Data.(*model.Post)
o4 := &model.Post{} o4 := &model.Post{}
o4.ChannelId = c1.Id o4.ChannelId = c1.Id
o4.UserId = model.NewId() o4.UserId = model.NewId()
o4.Hashtags = "#hashtag" o4.Hashtags = "#hashtag"
o4.Message = "(message)blargh" o4.Message = "(message)blargh"
o4 = (<-store.Post().Save(o4)).Data.(*model.Post) o4 = (<-store.Post().Save(utils.T, o4)).Data.(*model.Post)
o5 := &model.Post{} o5 := &model.Post{}
o5.ChannelId = c1.Id o5.ChannelId = c1.Id
o5.UserId = model.NewId() o5.UserId = model.NewId()
o5.Hashtags = "#secret #howdy" o5.Hashtags = "#secret #howdy"
o5 = (<-store.Post().Save(o5)).Data.(*model.Post) o5 = (<-store.Post().Save(utils.T, o5)).Data.(*model.Post)
r1 := (<-store.Post().Search(teamId, userId, &model.SearchParams{Terms: "corey", IsHashtag: false})).Data.(*model.PostList) r1 := (<-store.Post().Search(utils.T, teamId, userId, &model.SearchParams{Terms: "corey", IsHashtag: false})).Data.(*model.PostList)
if len(r1.Order) != 1 || r1.Order[0] != o1.Id { if len(r1.Order) != 1 || r1.Order[0] != o1.Id {
t.Fatal("returned wrong search result") t.Fatal("returned wrong search result")
} }
r3 := (<-store.Post().Search(teamId, userId, &model.SearchParams{Terms: "new", IsHashtag: false})).Data.(*model.PostList) r3 := (<-store.Post().Search(utils.T, teamId, userId, &model.SearchParams{Terms: "new", IsHashtag: false})).Data.(*model.PostList)
if len(r3.Order) != 2 || (r3.Order[0] != o1.Id && r3.Order[1] != o1.Id) { if len(r3.Order) != 2 || (r3.Order[0] != o1.Id && r3.Order[1] != o1.Id) {
t.Fatal("returned wrong search result") t.Fatal("returned wrong search result")
} }
r4 := (<-store.Post().Search(teamId, userId, &model.SearchParams{Terms: "john", IsHashtag: false})).Data.(*model.PostList) r4 := (<-store.Post().Search(utils.T, teamId, userId, &model.SearchParams{Terms: "john", IsHashtag: false})).Data.(*model.PostList)
if len(r4.Order) != 1 || r4.Order[0] != o2.Id { if len(r4.Order) != 1 || r4.Order[0] != o2.Id {
t.Fatal("returned wrong search result") t.Fatal("returned wrong search result")
} }
r5 := (<-store.Post().Search(teamId, userId, &model.SearchParams{Terms: "matter*", IsHashtag: false})).Data.(*model.PostList) r5 := (<-store.Post().Search(utils.T, teamId, userId, &model.SearchParams{Terms: "matter*", IsHashtag: false})).Data.(*model.PostList)
if len(r5.Order) != 1 || r5.Order[0] != o1.Id { if len(r5.Order) != 1 || r5.Order[0] != o1.Id {
t.Fatal("returned wrong search result") t.Fatal("returned wrong search result")
} }
r6 := (<-store.Post().Search(teamId, userId, &model.SearchParams{Terms: "#hashtag", IsHashtag: true})).Data.(*model.PostList) r6 := (<-store.Post().Search(utils.T, teamId, userId, &model.SearchParams{Terms: "#hashtag", IsHashtag: true})).Data.(*model.PostList)
if len(r6.Order) != 1 || r6.Order[0] != o4.Id { if len(r6.Order) != 1 || r6.Order[0] != o4.Id {
t.Fatal("returned wrong search result") t.Fatal("returned wrong search result")
} }
r7 := (<-store.Post().Search(teamId, userId, &model.SearchParams{Terms: "#secret", IsHashtag: true})).Data.(*model.PostList) r7 := (<-store.Post().Search(utils.T, teamId, userId, &model.SearchParams{Terms: "#secret", IsHashtag: true})).Data.(*model.PostList)
if len(r7.Order) != 1 || r7.Order[0] != o5.Id { if len(r7.Order) != 1 || r7.Order[0] != o5.Id {
t.Fatal("returned wrong search result") t.Fatal("returned wrong search result")
} }
r8 := (<-store.Post().Search(teamId, userId, &model.SearchParams{Terms: "@thisshouldmatchnothing", IsHashtag: true})).Data.(*model.PostList) r8 := (<-store.Post().Search(utils.T, teamId, userId, &model.SearchParams{Terms: "@thisshouldmatchnothing", IsHashtag: true})).Data.(*model.PostList)
if len(r8.Order) != 0 { if len(r8.Order) != 0 {
t.Fatal("returned wrong search result") t.Fatal("returned wrong search result")
} }
r9 := (<-store.Post().Search(teamId, userId, &model.SearchParams{Terms: "mattermost jersey", IsHashtag: false})).Data.(*model.PostList) r9 := (<-store.Post().Search(utils.T, teamId, userId, &model.SearchParams{Terms: "mattermost jersey", IsHashtag: false})).Data.(*model.PostList)
if len(r9.Order) != 2 { if len(r9.Order) != 2 {
t.Fatal("returned wrong search result") t.Fatal("returned wrong search result")
} }
r10 := (<-store.Post().Search(teamId, userId, &model.SearchParams{Terms: "matter* jer*", IsHashtag: false})).Data.(*model.PostList) r10 := (<-store.Post().Search(utils.T, teamId, userId, &model.SearchParams{Terms: "matter* jer*", IsHashtag: false})).Data.(*model.PostList)
if len(r10.Order) != 2 { if len(r10.Order) != 2 {
t.Fatal("returned wrong search result") t.Fatal("returned wrong search result")
} }
r11 := (<-store.Post().Search(teamId, userId, &model.SearchParams{Terms: "message blargh", IsHashtag: false})).Data.(*model.PostList) r11 := (<-store.Post().Search(utils.T, teamId, userId, &model.SearchParams{Terms: "message blargh", IsHashtag: false})).Data.(*model.PostList)
if len(r11.Order) != 1 { if len(r11.Order) != 1 {
t.Fatal("returned wrong search result") t.Fatal("returned wrong search result")
} }
r12 := (<-store.Post().Search(teamId, userId, &model.SearchParams{Terms: "blargh>", IsHashtag: false})).Data.(*model.PostList) r12 := (<-store.Post().Search(utils.T, teamId, userId, &model.SearchParams{Terms: "blargh>", IsHashtag: false})).Data.(*model.PostList)
if len(r12.Order) != 1 { if len(r12.Order) != 1 {
t.Fatal("returned wrong search result") t.Fatal("returned wrong search result")
} }
@@ -779,30 +779,30 @@ func TestUserCountsWithPostsByDay(t *testing.T) {
o1.UserId = model.NewId() o1.UserId = model.NewId()
o1.CreateAt = utils.MillisFromTime(utils.Yesterday()) o1.CreateAt = utils.MillisFromTime(utils.Yesterday())
o1.Message = "a" + model.NewId() + "b" o1.Message = "a" + model.NewId() + "b"
o1 = Must(store.Post().Save(o1)).(*model.Post) o1 = Must(store.Post().Save(utils.T, o1)).(*model.Post)
o1a := &model.Post{} o1a := &model.Post{}
o1a.ChannelId = c1.Id o1a.ChannelId = c1.Id
o1a.UserId = model.NewId() o1a.UserId = model.NewId()
o1a.CreateAt = o1.CreateAt o1a.CreateAt = o1.CreateAt
o1a.Message = "a" + model.NewId() + "b" o1a.Message = "a" + model.NewId() + "b"
o1a = Must(store.Post().Save(o1a)).(*model.Post) o1a = Must(store.Post().Save(utils.T, o1a)).(*model.Post)
o2 := &model.Post{} o2 := &model.Post{}
o2.ChannelId = c1.Id o2.ChannelId = c1.Id
o2.UserId = model.NewId() o2.UserId = model.NewId()
o2.CreateAt = o1.CreateAt - (1000 * 60 * 60 * 24) o2.CreateAt = o1.CreateAt - (1000 * 60 * 60 * 24)
o2.Message = "a" + model.NewId() + "b" o2.Message = "a" + model.NewId() + "b"
o2 = Must(store.Post().Save(o2)).(*model.Post) o2 = Must(store.Post().Save(utils.T, o2)).(*model.Post)
o2a := &model.Post{} o2a := &model.Post{}
o2a.ChannelId = c1.Id o2a.ChannelId = c1.Id
o2a.UserId = o2.UserId o2a.UserId = o2.UserId
o2a.CreateAt = o1.CreateAt - (1000 * 60 * 60 * 24) o2a.CreateAt = o1.CreateAt - (1000 * 60 * 60 * 24)
o2a.Message = "a" + model.NewId() + "b" o2a.Message = "a" + model.NewId() + "b"
o2a = Must(store.Post().Save(o2a)).(*model.Post) o2a = Must(store.Post().Save(utils.T, o2a)).(*model.Post)
if r1 := <-store.Post().AnalyticsUserCountsWithPostsByDay(t1.Id); r1.Err != nil { if r1 := <-store.Post().AnalyticsUserCountsWithPostsByDay(utils.T, t1.Id); r1.Err != nil {
t.Fatal(r1.Err) t.Fatal(r1.Err)
} else { } else {
row1 := r1.Data.(model.AnalyticsRows)[0] row1 := r1.Data.(model.AnalyticsRows)[0]
@@ -839,33 +839,33 @@ func TestPostCountsByDay(t *testing.T) {
o1.UserId = model.NewId() o1.UserId = model.NewId()
o1.CreateAt = utils.MillisFromTime(utils.Yesterday()) o1.CreateAt = utils.MillisFromTime(utils.Yesterday())
o1.Message = "a" + model.NewId() + "b" o1.Message = "a" + model.NewId() + "b"
o1 = Must(store.Post().Save(o1)).(*model.Post) o1 = Must(store.Post().Save(utils.T, o1)).(*model.Post)
o1a := &model.Post{} o1a := &model.Post{}
o1a.ChannelId = c1.Id o1a.ChannelId = c1.Id
o1a.UserId = model.NewId() o1a.UserId = model.NewId()
o1a.CreateAt = o1.CreateAt o1a.CreateAt = o1.CreateAt
o1a.Message = "a" + model.NewId() + "b" o1a.Message = "a" + model.NewId() + "b"
o1a = Must(store.Post().Save(o1a)).(*model.Post) o1a = Must(store.Post().Save(utils.T, o1a)).(*model.Post)
o2 := &model.Post{} o2 := &model.Post{}
o2.ChannelId = c1.Id o2.ChannelId = c1.Id
o2.UserId = model.NewId() o2.UserId = model.NewId()
o2.CreateAt = o1.CreateAt - (1000 * 60 * 60 * 24 * 2) o2.CreateAt = o1.CreateAt - (1000 * 60 * 60 * 24 * 2)
o2.Message = "a" + model.NewId() + "b" o2.Message = "a" + model.NewId() + "b"
o2 = Must(store.Post().Save(o2)).(*model.Post) o2 = Must(store.Post().Save(utils.T, o2)).(*model.Post)
o2a := &model.Post{} o2a := &model.Post{}
o2a.ChannelId = c1.Id o2a.ChannelId = c1.Id
o2a.UserId = o2.UserId o2a.UserId = o2.UserId
o2a.CreateAt = o1.CreateAt - (1000 * 60 * 60 * 24 * 2) o2a.CreateAt = o1.CreateAt - (1000 * 60 * 60 * 24 * 2)
o2a.Message = "a" + model.NewId() + "b" o2a.Message = "a" + model.NewId() + "b"
o2a = Must(store.Post().Save(o2a)).(*model.Post) o2a = Must(store.Post().Save(utils.T, o2a)).(*model.Post)
time.Sleep(1 * time.Second) time.Sleep(1 * time.Second)
t.Log(t1.Id) t.Log(t1.Id)
if r1 := <-store.Post().AnalyticsPostCountsByDay(t1.Id); r1.Err != nil { if r1 := <-store.Post().AnalyticsPostCountsByDay(utils.T, t1.Id); r1.Err != nil {
t.Fatal(r1.Err) t.Fatal(r1.Err)
} else { } else {
row1 := r1.Data.(model.AnalyticsRows)[0] row1 := r1.Data.(model.AnalyticsRows)[0]
@@ -880,7 +880,7 @@ func TestPostCountsByDay(t *testing.T) {
} }
} }
if r1 := <-store.Post().AnalyticsPostCount(t1.Id); r1.Err != nil { if r1 := <-store.Post().AnalyticsPostCount(utils.T, t1.Id); r1.Err != nil {
t.Fatal(r1.Err) t.Fatal(r1.Err)
} else { } else {
if r1.Data.(int64) != 4 { if r1.Data.(int64) != 4 {

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

@@ -88,21 +88,21 @@ type ChannelStore interface {
} }
type PostStore interface { type PostStore interface {
Save(post *model.Post) StoreChannel Save(T goi18n.TranslateFunc, post *model.Post) StoreChannel
Update(post *model.Post, newMessage string, newHashtags string) StoreChannel Update(T goi18n.TranslateFunc, post *model.Post, newMessage string, newHashtags string) StoreChannel
Get(id string) StoreChannel Get(T goi18n.TranslateFunc, id string) StoreChannel
Delete(postId string, time int64) StoreChannel Delete(T goi18n.TranslateFunc, postId string, time int64) StoreChannel
PermanentDeleteByUser(userId string) StoreChannel PermanentDeleteByUser(T goi18n.TranslateFunc, userId string) StoreChannel
GetPosts(channelId string, offset int, limit int) StoreChannel GetPosts(T goi18n.TranslateFunc, channelId string, offset int, limit int) StoreChannel
GetPostsBefore(channelId string, postId string, numPosts int, offset int) StoreChannel GetPostsBefore(T goi18n.TranslateFunc, channelId string, postId string, numPosts int, offset int) StoreChannel
GetPostsAfter(channelId string, postId string, numPosts int, offset int) StoreChannel GetPostsAfter(T goi18n.TranslateFunc, channelId string, postId string, numPosts int, offset int) StoreChannel
GetPostsSince(channelId string, time int64) StoreChannel GetPostsSince(T goi18n.TranslateFunc, channelId string, time int64) StoreChannel
GetEtag(channelId string) StoreChannel GetEtag(T goi18n.TranslateFunc, channelId string) StoreChannel
Search(teamId string, userId string, params *model.SearchParams) StoreChannel Search(T goi18n.TranslateFunc, teamId string, userId string, params *model.SearchParams) StoreChannel
GetForExport(channelId string) StoreChannel GetForExport(T goi18n.TranslateFunc, channelId string) StoreChannel
AnalyticsUserCountsWithPostsByDay(teamId string) StoreChannel AnalyticsUserCountsWithPostsByDay(T goi18n.TranslateFunc, teamId string) StoreChannel
AnalyticsPostCountsByDay(teamId string) StoreChannel AnalyticsPostCountsByDay(T goi18n.TranslateFunc, teamId string) StoreChannel
AnalyticsPostCount(teamId string) StoreChannel AnalyticsPostCount(T goi18n.TranslateFunc, teamId string) StoreChannel
} }
type UserStore interface { type UserStore interface {

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

@@ -370,7 +370,7 @@ func postPermalink(c *api.Context, w http.ResponseWriter, r *http.Request) {
} }
var post *model.Post var post *model.Post
if result := <-api.Srv.Store.Post().Get(postId); result.Err != nil { if result := <-api.Srv.Store.Post().Get(c.T, postId); result.Err != nil {
c.Err = result.Err c.Err = result.Err
return return
} else { } else {