Commit aac8d121 authored by =Corey Hulen's avatar =Corey Hulen

PLT-7 adding loc db calls for posts table

parent 3ac5ecf0
......@@ -159,7 +159,7 @@ func getAnalytics(c *Context, w http.ResponseWriter, r *http.Request) {
rows[2] = &model.AnalyticsRow{"post_count", 0}
openChan := Srv.Store.Channel().AnalyticsTypeCount(c.T, teamId, model.CHANNEL_OPEN)
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 {
c.Err = r.Err
......@@ -184,14 +184,14 @@ func getAnalytics(c *Context, w http.ResponseWriter, r *http.Request) {
w.Write([]byte(rows.ToJson()))
} 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
return
} else {
w.Write([]byte(r.Data.(model.AnalyticsRows).ToJson()))
}
} 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
return
} else {
......
......@@ -192,7 +192,7 @@ func ExportChannels(T goi18n.TranslateFunc, writer ExportWriter, options *Export
}
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
}
}
......@@ -200,10 +200,10 @@ func ExportChannels(T goi18n.TranslateFunc, writer ExportWriter, options *Export
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
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
} else {
posts = result.Data.([]*model.Post)
......
......@@ -14,10 +14,10 @@ import (
// 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)
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)
}
}
......
......@@ -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) {
var pchan store.StoreChannel
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
......@@ -138,7 +138,7 @@ func CreatePost(c *Context, post *model.Post, triggerWebhooks bool) (*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
} else {
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)
pchan := Srv.Store.Post().Get(post.Id)
pchan := Srv.Store.Post().Get(c.T, post.Id)
if !c.HasPermissionsToChannel(cchan, "updatePost") {
return
......@@ -745,7 +745,7 @@ func updatePost(c *Context, w http.ResponseWriter, r *http.Request) {
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
return
} 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)
etagChan := Srv.Store.Post().GetEtag(id)
etagChan := Srv.Store.Post().GetEtag(c.T, id)
if !c.HasPermissionsToChannel(cchan, "getPosts") {
return
......@@ -794,7 +794,7 @@ func getPosts(c *Context, w http.ResponseWriter, r *http.Request) {
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 {
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)
pchan := Srv.Store.Post().GetPostsSince(id, time)
pchan := Srv.Store.Post().GetPostsSince(c.T, id, time)
if !c.HasPermissionsToChannel(cchan, "getPostsSince") {
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)
pchan := Srv.Store.Post().Get(postId)
pchan := Srv.Store.Post().Get(c.T, postId)
if !c.HasPermissionsToChannel(cchan, "getPost") {
return
......@@ -891,7 +891,7 @@ func getPostById(c *Context, w http.ResponseWriter, r *http.Request) {
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
return
} 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)
pchan := Srv.Store.Post().Get(postId)
pchan := Srv.Store.Post().Get(c.T, postId)
if result := <-pchan; result.Err != nil {
c.Err = result.Err
......@@ -963,7 +963,7 @@ func deletePost(c *Context, w http.ResponseWriter, r *http.Request) {
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
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)
// 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") {
return
......@@ -1027,9 +1027,9 @@ func getPostsBeforeOrAfter(c *Context, w http.ResponseWriter, r *http.Request, b
var pchan store.StoreChannel
if before {
pchan = Srv.Store.Post().GetPostsBefore(id, postId, numPosts, offset)
pchan = Srv.Store.Post().GetPostsBefore(c.T, id, postId, numPosts, offset)
} 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 {
......@@ -1057,7 +1057,7 @@ func searchPosts(c *Context, w http.ResponseWriter, r *http.Request) {
for _, params := range paramsList {
// don't allow users to search for everything
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
}
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 {
switch {
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,
CreateAt: SlackConvertTimeStamp(sPost.TimeStamp),
}
ImportPost(&newPost)
ImportPost(T, &newPost)
case sPost.Type == "message" && sPost.SubType == "file_comment":
if sPost.Comment["user"] == "" {
l4g.Debug("Message without user")
......@@ -161,7 +161,7 @@ func SlackAddPosts(channel *model.Channel, posts []SlackPost, users map[string]*
Message: sPost.Comment["comment"],
CreateAt: SlackConvertTimeStamp(sPost.TimeStamp),
}
ImportPost(&newPost)
ImportPost(T, &newPost)
case sPost.Type == "message" && sPost.SubType == "bot_message":
// 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
......@@ -200,7 +200,7 @@ func SlackAddChannels(T goi18n.TranslateFunc, teamId string, slackchannels []Sla
}
log.WriteString(newChannel.DisplayName + "\r\n")
addedChannels[sChannel.Id] = mChannel
SlackAddPosts(mChannel, posts[sChannel.Name], users)
SlackAddPosts(T, mChannel, posts[sChannel.Name], users)
}
return addedChannels
......
......@@ -1460,7 +1460,7 @@ func PermanentDeleteUser(c *Context, user *model.User) *model.AppError {
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
}
......
......@@ -11,6 +11,7 @@ import (
"github.com/mattermost/platform/model"
"github.com/mattermost/platform/utils"
goi18n "github.com/nicksnyder/go-i18n/i18n"
)
type SqlPostStore struct {
......@@ -50,7 +51,7 @@ func (s SqlPostStore) CreateIndexesIfNotExists() {
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)
go func() {
......@@ -97,7 +98,7 @@ func (s SqlPostStore) Save(post *model.Post) 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)
go func() {
......@@ -142,7 +143,7 @@ func (s SqlPostStore) Update(oldPost *model.Post, newMessage string, newHashtags
return storeChannel
}
func (s SqlPostStore) Get(id string) StoreChannel {
func (s SqlPostStore) Get(T goi18n.TranslateFunc, id string) StoreChannel {
storeChannel := make(StoreChannel)
go func() {
......@@ -188,7 +189,7 @@ type etagPosts struct {
UpdateAt int64
}
func (s SqlPostStore) GetEtag(channelId string) StoreChannel {
func (s SqlPostStore) GetEtag(T goi18n.TranslateFunc, channelId string) StoreChannel {
storeChannel := make(StoreChannel)
go func() {
......@@ -209,7 +210,7 @@ func (s SqlPostStore) GetEtag(channelId string) 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)
go func() {
......@@ -227,7 +228,7 @@ func (s SqlPostStore) Delete(postId string, time int64) StoreChannel {
return storeChannel
}
func (s SqlPostStore) permanentDelete(postId string) StoreChannel {
func (s SqlPostStore) permanentDelete(T goi18n.TranslateFunc, postId string) StoreChannel {
storeChannel := make(StoreChannel)
go func() {
......@@ -245,7 +246,7 @@ func (s SqlPostStore) permanentDelete(postId string) StoreChannel {
return storeChannel
}
func (s SqlPostStore) permanentDeleteAllCommentByUser(userId string) StoreChannel {
func (s SqlPostStore) permanentDeleteAllCommentByUser(T goi18n.TranslateFunc, userId string) StoreChannel {
storeChannel := make(StoreChannel)
go func() {
......@@ -263,14 +264,14 @@ func (s SqlPostStore) permanentDeleteAllCommentByUser(userId string) StoreChanne
return storeChannel
}
func (s SqlPostStore) PermanentDeleteByUser(userId string) StoreChannel {
func (s SqlPostStore) PermanentDeleteByUser(T goi18n.TranslateFunc, userId string) StoreChannel {
storeChannel := make(StoreChannel)
go func() {
result := StoreResult{}
// 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
storeChannel <- result
close(storeChannel)
......@@ -294,7 +295,7 @@ func (s SqlPostStore) PermanentDeleteByUser(userId string) StoreChannel {
found = false
for _, id := range ids {
found = true
if r := <-s.permanentDelete(id); r.Err != nil {
if r := <-s.permanentDelete(T, id); r.Err != nil {
result.Err = r.Err
storeChannel <- result
close(storeChannel)
......@@ -320,7 +321,7 @@ func (s SqlPostStore) PermanentDeleteByUser(userId string) 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)
go func() {
......@@ -333,8 +334,8 @@ func (s SqlPostStore) GetPosts(channelId string, offset int, limit int) StoreCha
return
}
rpc := s.getRootPosts(channelId, offset, limit)
cpc := s.getParentsPosts(channelId, offset, limit)
rpc := s.getRootPosts(T, channelId, offset, limit)
cpc := s.getParentsPosts(T, channelId, offset, limit)
if rpr := <-rpc; rpr.Err != nil {
result.Err = rpr.Err
......@@ -367,7 +368,7 @@ func (s SqlPostStore) GetPosts(channelId string, offset int, limit int) StoreCha
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)
go func() {
......@@ -425,15 +426,15 @@ func (s SqlPostStore) GetPostsSince(channelId string, time int64) StoreChannel {
return storeChannel
}
func (s SqlPostStore) GetPostsBefore(channelId string, postId string, numPosts int, offset int) StoreChannel {
return s.getPostsAround(channelId, postId, numPosts, offset, true)
func (s SqlPostStore) GetPostsBefore(T goi18n.TranslateFunc, channelId string, postId string, numPosts int, offset int) StoreChannel {
return s.getPostsAround(T, channelId, postId, numPosts, offset, true)
}
func (s SqlPostStore) GetPostsAfter(channelId string, postId string, numPosts int, offset int) StoreChannel {
return s.getPostsAround(channelId, postId, numPosts, offset, false)
func (s SqlPostStore) GetPostsAfter(T goi18n.TranslateFunc, channelId string, postId string, numPosts int, offset int) StoreChannel {
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)
go func() {
......@@ -523,7 +524,7 @@ func (s SqlPostStore) getPostsAround(channelId string, postId string, numPosts i
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)
go func() {
......@@ -544,7 +545,7 @@ func (s SqlPostStore) getRootPosts(channelId string, offset int, limit int) Stor
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)
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)
go func() {
......@@ -765,7 +766,7 @@ func (s SqlPostStore) Search(teamId string, userId string, params *model.SearchP
return storeChannel
}
func (s SqlPostStore) GetForExport(channelId string) StoreChannel {
func (s SqlPostStore) GetForExport(T goi18n.TranslateFunc, channelId string) StoreChannel {
storeChannel := make(StoreChannel)
go func() {
......@@ -789,7 +790,7 @@ func (s SqlPostStore) GetForExport(channelId string) StoreChannel {
return storeChannel
}
func (s SqlPostStore) AnalyticsUserCountsWithPostsByDay(teamId string) StoreChannel {
func (s SqlPostStore) AnalyticsUserCountsWithPostsByDay(T goi18n.TranslateFunc, teamId string) StoreChannel {
storeChannel := make(StoreChannel)
go func() {
......@@ -853,7 +854,7 @@ func (s SqlPostStore) AnalyticsUserCountsWithPostsByDay(teamId string) StoreChan
return storeChannel
}
func (s SqlPostStore) AnalyticsPostCountsByDay(teamId string) StoreChannel {
func (s SqlPostStore) AnalyticsPostCountsByDay(T goi18n.TranslateFunc, teamId string) StoreChannel {
storeChannel := make(StoreChannel)
go func() {
......@@ -918,7 +919,7 @@ func (s SqlPostStore) AnalyticsPostCountsByDay(teamId string) StoreChannel {
return storeChannel
}
func (s SqlPostStore) AnalyticsPostCount(teamId string) StoreChannel {
func (s SqlPostStore) AnalyticsPostCount(T goi18n.TranslateFunc, teamId string) StoreChannel {
storeChannel := make(StoreChannel)
go func() {
......
This diff is collapsed.
......@@ -88,21 +88,21 @@ type ChannelStore interface {
}
type PostStore interface {
Save(post *model.Post) StoreChannel
Update(post *model.Post, newMessage string, newHashtags string) StoreChannel
Get(id string) StoreChannel
Delete(postId string, time int64) StoreChannel
PermanentDeleteByUser(userId string) StoreChannel
GetPosts(channelId string, offset int, limit int) StoreChannel
GetPostsBefore(channelId string, postId string, numPosts int, offset int) StoreChannel
GetPostsAfter(channelId string, postId string, numPosts int, offset int) StoreChannel
GetPostsSince(channelId string, time int64) StoreChannel
GetEtag(channelId string) StoreChannel
Search(teamId string, userId string, params *model.SearchParams) StoreChannel
GetForExport(channelId string) StoreChannel
AnalyticsUserCountsWithPostsByDay(teamId string) StoreChannel
AnalyticsPostCountsByDay(teamId string) StoreChannel
AnalyticsPostCount(teamId string) StoreChannel
Save(T goi18n.TranslateFunc, post *model.Post) StoreChannel
Update(T goi18n.TranslateFunc, post *model.Post, newMessage string, newHashtags string) StoreChannel
Get(T goi18n.TranslateFunc, id string) StoreChannel
Delete(T goi18n.TranslateFunc, postId string, time int64) StoreChannel
PermanentDeleteByUser(T goi18n.TranslateFunc, userId string) StoreChannel
GetPosts(T goi18n.TranslateFunc, channelId string, offset int, limit int) StoreChannel
GetPostsBefore(T goi18n.TranslateFunc, channelId string, postId string, numPosts int, offset int) StoreChannel
GetPostsAfter(T goi18n.TranslateFunc, channelId string, postId string, numPosts int, offset int) StoreChannel
GetPostsSince(T goi18n.TranslateFunc, channelId string, time int64) StoreChannel
GetEtag(T goi18n.TranslateFunc, channelId string) StoreChannel
Search(T goi18n.TranslateFunc, teamId string, userId string, params *model.SearchParams) StoreChannel
GetForExport(T goi18n.TranslateFunc, channelId string) StoreChannel
AnalyticsUserCountsWithPostsByDay(T goi18n.TranslateFunc, teamId string) StoreChannel
AnalyticsPostCountsByDay(T goi18n.TranslateFunc, teamId string) StoreChannel
AnalyticsPostCount(T goi18n.TranslateFunc, teamId string) StoreChannel
}
type UserStore interface {
......
......@@ -370,7 +370,7 @@ func postPermalink(c *api.Context, w http.ResponseWriter, r *http.Request) {
}
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
return
} else {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment