Remove insights (#23952)
* removed server side * Updated store layer * unused import * Updated autogenerated code template * Updated tests * lint fix * unused translations * webapp side * Updated i18n * lint fix: * type fix * Updated snapshots * Removed insights from API specs * updated e2e * Updated e2e tests * Updated e2e tests * Removed insights tests * Removed Insights as possible channel to load in sidebar from test * Removed more insights tests * More e2e fixed * More cleanup * Lint * More cleanup in client4 and boards api * More cleanup * Fixes * lint fix --------- Co-authored-by: maria.nunez <maria.nunez@mattermost.com> Co-authored-by: Mattermost Build <build@mattermost.com>
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
e37459cd00
Коммит
26617fcbdc
@@ -8,7 +8,6 @@ package opentracinglayer
|
||||
|
||||
import (
|
||||
"context"
|
||||
"time"
|
||||
|
||||
"github.com/mattermost/mattermost/server/public/model"
|
||||
"github.com/mattermost/mattermost/server/v8/platform/services/tracing"
|
||||
|
||||
@@ -9,7 +9,6 @@ package retrylayer
|
||||
import (
|
||||
"context"
|
||||
timepkg "time"
|
||||
"time"
|
||||
|
||||
"github.com/lib/pq"
|
||||
"github.com/mattermost/mattermost/server/public/model"
|
||||
|
||||
@@ -8,7 +8,6 @@ package opentracinglayer
|
||||
|
||||
import (
|
||||
"context"
|
||||
"time"
|
||||
|
||||
"github.com/mattermost/mattermost/server/public/model"
|
||||
"github.com/mattermost/mattermost/server/v8/channels/store"
|
||||
@@ -1876,78 +1875,6 @@ func (s *OpenTracingLayerChannelStore) GetTeamMembersForChannel(channelID string
|
||||
return result, err
|
||||
}
|
||||
|
||||
func (s *OpenTracingLayerChannelStore) GetTopChannelsForTeamSince(teamID string, userID string, since int64, offset int, limit int) (*model.TopChannelList, error) {
|
||||
origCtx := s.Root.Store.Context()
|
||||
span, newCtx := tracing.StartSpanWithParentByContext(s.Root.Store.Context(), "ChannelStore.GetTopChannelsForTeamSince")
|
||||
s.Root.Store.SetContext(newCtx)
|
||||
defer func() {
|
||||
s.Root.Store.SetContext(origCtx)
|
||||
}()
|
||||
|
||||
defer span.Finish()
|
||||
result, err := s.ChannelStore.GetTopChannelsForTeamSince(teamID, userID, since, offset, limit)
|
||||
if err != nil {
|
||||
span.LogFields(spanlog.Error(err))
|
||||
ext.Error.Set(span, true)
|
||||
}
|
||||
|
||||
return result, err
|
||||
}
|
||||
|
||||
func (s *OpenTracingLayerChannelStore) GetTopChannelsForUserSince(userID string, teamID string, since int64, offset int, limit int) (*model.TopChannelList, error) {
|
||||
origCtx := s.Root.Store.Context()
|
||||
span, newCtx := tracing.StartSpanWithParentByContext(s.Root.Store.Context(), "ChannelStore.GetTopChannelsForUserSince")
|
||||
s.Root.Store.SetContext(newCtx)
|
||||
defer func() {
|
||||
s.Root.Store.SetContext(origCtx)
|
||||
}()
|
||||
|
||||
defer span.Finish()
|
||||
result, err := s.ChannelStore.GetTopChannelsForUserSince(userID, teamID, since, offset, limit)
|
||||
if err != nil {
|
||||
span.LogFields(spanlog.Error(err))
|
||||
ext.Error.Set(span, true)
|
||||
}
|
||||
|
||||
return result, err
|
||||
}
|
||||
|
||||
func (s *OpenTracingLayerChannelStore) GetTopInactiveChannelsForTeamSince(teamID string, userID string, since int64, offset int, limit int) (*model.TopInactiveChannelList, error) {
|
||||
origCtx := s.Root.Store.Context()
|
||||
span, newCtx := tracing.StartSpanWithParentByContext(s.Root.Store.Context(), "ChannelStore.GetTopInactiveChannelsForTeamSince")
|
||||
s.Root.Store.SetContext(newCtx)
|
||||
defer func() {
|
||||
s.Root.Store.SetContext(origCtx)
|
||||
}()
|
||||
|
||||
defer span.Finish()
|
||||
result, err := s.ChannelStore.GetTopInactiveChannelsForTeamSince(teamID, userID, since, offset, limit)
|
||||
if err != nil {
|
||||
span.LogFields(spanlog.Error(err))
|
||||
ext.Error.Set(span, true)
|
||||
}
|
||||
|
||||
return result, err
|
||||
}
|
||||
|
||||
func (s *OpenTracingLayerChannelStore) GetTopInactiveChannelsForUserSince(teamID string, userID string, since int64, offset int, limit int) (*model.TopInactiveChannelList, error) {
|
||||
origCtx := s.Root.Store.Context()
|
||||
span, newCtx := tracing.StartSpanWithParentByContext(s.Root.Store.Context(), "ChannelStore.GetTopInactiveChannelsForUserSince")
|
||||
s.Root.Store.SetContext(newCtx)
|
||||
defer func() {
|
||||
s.Root.Store.SetContext(origCtx)
|
||||
}()
|
||||
|
||||
defer span.Finish()
|
||||
result, err := s.ChannelStore.GetTopInactiveChannelsForUserSince(teamID, userID, since, offset, limit)
|
||||
if err != nil {
|
||||
span.LogFields(spanlog.Error(err))
|
||||
ext.Error.Set(span, true)
|
||||
}
|
||||
|
||||
return result, err
|
||||
}
|
||||
|
||||
func (s *OpenTracingLayerChannelStore) GroupSyncedChannelCount() (int64, error) {
|
||||
origCtx := s.Root.Store.Context()
|
||||
span, newCtx := tracing.StartSpanWithParentByContext(s.Root.Store.Context(), "ChannelStore.GroupSyncedChannelCount")
|
||||
@@ -2178,24 +2105,6 @@ func (s *OpenTracingLayerChannelStore) PermanentDeleteMembersByUser(userID strin
|
||||
return err
|
||||
}
|
||||
|
||||
func (s *OpenTracingLayerChannelStore) PostCountsByDuration(channelIDs []string, sinceUnixMillis int64, userID *string, duration model.PostCountGrouping, groupingLocation *time.Location) ([]*model.DurationPostCount, error) {
|
||||
origCtx := s.Root.Store.Context()
|
||||
span, newCtx := tracing.StartSpanWithParentByContext(s.Root.Store.Context(), "ChannelStore.PostCountsByDuration")
|
||||
s.Root.Store.SetContext(newCtx)
|
||||
defer func() {
|
||||
s.Root.Store.SetContext(origCtx)
|
||||
}()
|
||||
|
||||
defer span.Finish()
|
||||
result, err := s.ChannelStore.PostCountsByDuration(channelIDs, sinceUnixMillis, userID, duration, groupingLocation)
|
||||
if err != nil {
|
||||
span.LogFields(spanlog.Error(err))
|
||||
ext.Error.Set(span, true)
|
||||
}
|
||||
|
||||
return result, err
|
||||
}
|
||||
|
||||
func (s *OpenTracingLayerChannelStore) RemoveAllDeactivatedMembers(channelID string) error {
|
||||
origCtx := s.Root.Store.Context()
|
||||
span, newCtx := tracing.StartSpanWithParentByContext(s.Root.Store.Context(), "ChannelStore.RemoveAllDeactivatedMembers")
|
||||
@@ -6458,24 +6367,6 @@ func (s *OpenTracingLayerPostStore) GetSingle(id string, inclDeleted bool) (*mod
|
||||
return result, err
|
||||
}
|
||||
|
||||
func (s *OpenTracingLayerPostStore) GetTopDMsForUserSince(userID string, since int64, offset int, limit int) (*model.TopDMList, error) {
|
||||
origCtx := s.Root.Store.Context()
|
||||
span, newCtx := tracing.StartSpanWithParentByContext(s.Root.Store.Context(), "PostStore.GetTopDMsForUserSince")
|
||||
s.Root.Store.SetContext(newCtx)
|
||||
defer func() {
|
||||
s.Root.Store.SetContext(origCtx)
|
||||
}()
|
||||
|
||||
defer span.Finish()
|
||||
result, err := s.PostStore.GetTopDMsForUserSince(userID, since, offset, limit)
|
||||
if err != nil {
|
||||
span.LogFields(spanlog.Error(err))
|
||||
ext.Error.Set(span, true)
|
||||
}
|
||||
|
||||
return result, err
|
||||
}
|
||||
|
||||
func (s *OpenTracingLayerPostStore) HasAutoResponsePostByUserSince(options model.GetPostsSinceOptions, userId string) (bool, error) {
|
||||
origCtx := s.Root.Store.Context()
|
||||
span, newCtx := tracing.StartSpanWithParentByContext(s.Root.Store.Context(), "PostStore.HasAutoResponsePostByUserSince")
|
||||
@@ -7353,42 +7244,6 @@ func (s *OpenTracingLayerReactionStore) GetForPostSince(postId string, since int
|
||||
return result, err
|
||||
}
|
||||
|
||||
func (s *OpenTracingLayerReactionStore) GetTopForTeamSince(teamID string, userID string, since int64, offset int, limit int) (*model.TopReactionList, error) {
|
||||
origCtx := s.Root.Store.Context()
|
||||
span, newCtx := tracing.StartSpanWithParentByContext(s.Root.Store.Context(), "ReactionStore.GetTopForTeamSince")
|
||||
s.Root.Store.SetContext(newCtx)
|
||||
defer func() {
|
||||
s.Root.Store.SetContext(origCtx)
|
||||
}()
|
||||
|
||||
defer span.Finish()
|
||||
result, err := s.ReactionStore.GetTopForTeamSince(teamID, userID, since, offset, limit)
|
||||
if err != nil {
|
||||
span.LogFields(spanlog.Error(err))
|
||||
ext.Error.Set(span, true)
|
||||
}
|
||||
|
||||
return result, err
|
||||
}
|
||||
|
||||
func (s *OpenTracingLayerReactionStore) GetTopForUserSince(userID string, teamID string, since int64, offset int, limit int) (*model.TopReactionList, error) {
|
||||
origCtx := s.Root.Store.Context()
|
||||
span, newCtx := tracing.StartSpanWithParentByContext(s.Root.Store.Context(), "ReactionStore.GetTopForUserSince")
|
||||
s.Root.Store.SetContext(newCtx)
|
||||
defer func() {
|
||||
s.Root.Store.SetContext(origCtx)
|
||||
}()
|
||||
|
||||
defer span.Finish()
|
||||
result, err := s.ReactionStore.GetTopForUserSince(userID, teamID, since, offset, limit)
|
||||
if err != nil {
|
||||
span.LogFields(spanlog.Error(err))
|
||||
ext.Error.Set(span, true)
|
||||
}
|
||||
|
||||
return result, err
|
||||
}
|
||||
|
||||
func (s *OpenTracingLayerReactionStore) PermanentDeleteBatch(endTime int64, limit int64) (int64, error) {
|
||||
origCtx := s.Root.Store.Context()
|
||||
span, newCtx := tracing.StartSpanWithParentByContext(s.Root.Store.Context(), "ReactionStore.PermanentDeleteBatch")
|
||||
@@ -9634,24 +9489,6 @@ func (s *OpenTracingLayerTeamStore) GetMembersByIds(teamID string, userIds []str
|
||||
return result, err
|
||||
}
|
||||
|
||||
func (s *OpenTracingLayerTeamStore) GetNewTeamMembersSince(teamID string, since int64, offset int, limit int, showFullName bool) (*model.NewTeamMembersList, int64, error) {
|
||||
origCtx := s.Root.Store.Context()
|
||||
span, newCtx := tracing.StartSpanWithParentByContext(s.Root.Store.Context(), "TeamStore.GetNewTeamMembersSince")
|
||||
s.Root.Store.SetContext(newCtx)
|
||||
defer func() {
|
||||
s.Root.Store.SetContext(origCtx)
|
||||
}()
|
||||
|
||||
defer span.Finish()
|
||||
result, resultVar1, err := s.TeamStore.GetNewTeamMembersSince(teamID, since, offset, limit, showFullName)
|
||||
if err != nil {
|
||||
span.LogFields(spanlog.Error(err))
|
||||
ext.Error.Set(span, true)
|
||||
}
|
||||
|
||||
return result, resultVar1, err
|
||||
}
|
||||
|
||||
func (s *OpenTracingLayerTeamStore) GetTeamMembersForExport(userID string) ([]*model.TeamMemberForExport, error) {
|
||||
origCtx := s.Root.Store.Context()
|
||||
span, newCtx := tracing.StartSpanWithParentByContext(s.Root.Store.Context(), "TeamStore.GetTeamMembersForExport")
|
||||
@@ -10421,42 +10258,6 @@ func (s *OpenTracingLayerThreadStore) GetThreadsForUser(userId string, teamID st
|
||||
return result, err
|
||||
}
|
||||
|
||||
func (s *OpenTracingLayerThreadStore) GetTopThreadsForTeamSince(teamID string, userID string, since int64, offset int, limit int) (*model.TopThreadList, error) {
|
||||
origCtx := s.Root.Store.Context()
|
||||
span, newCtx := tracing.StartSpanWithParentByContext(s.Root.Store.Context(), "ThreadStore.GetTopThreadsForTeamSince")
|
||||
s.Root.Store.SetContext(newCtx)
|
||||
defer func() {
|
||||
s.Root.Store.SetContext(origCtx)
|
||||
}()
|
||||
|
||||
defer span.Finish()
|
||||
result, err := s.ThreadStore.GetTopThreadsForTeamSince(teamID, userID, since, offset, limit)
|
||||
if err != nil {
|
||||
span.LogFields(spanlog.Error(err))
|
||||
ext.Error.Set(span, true)
|
||||
}
|
||||
|
||||
return result, err
|
||||
}
|
||||
|
||||
func (s *OpenTracingLayerThreadStore) GetTopThreadsForUserSince(teamID string, userID string, since int64, offset int, limit int) (*model.TopThreadList, error) {
|
||||
origCtx := s.Root.Store.Context()
|
||||
span, newCtx := tracing.StartSpanWithParentByContext(s.Root.Store.Context(), "ThreadStore.GetTopThreadsForUserSince")
|
||||
s.Root.Store.SetContext(newCtx)
|
||||
defer func() {
|
||||
s.Root.Store.SetContext(origCtx)
|
||||
}()
|
||||
|
||||
defer span.Finish()
|
||||
result, err := s.ThreadStore.GetTopThreadsForUserSince(teamID, userID, since, offset, limit)
|
||||
if err != nil {
|
||||
span.LogFields(spanlog.Error(err))
|
||||
ext.Error.Set(span, true)
|
||||
}
|
||||
|
||||
return result, err
|
||||
}
|
||||
|
||||
func (s *OpenTracingLayerThreadStore) GetTotalThreads(userId string, teamID string, opts model.GetUserThreadsOpts) (int64, error) {
|
||||
origCtx := s.Root.Store.Context()
|
||||
span, newCtx := tracing.StartSpanWithParentByContext(s.Root.Store.Context(), "ThreadStore.GetTotalThreads")
|
||||
|
||||
@@ -8,7 +8,6 @@ package retrylayer
|
||||
|
||||
import (
|
||||
"context"
|
||||
"time"
|
||||
timepkg "time"
|
||||
|
||||
"github.com/go-sql-driver/mysql"
|
||||
@@ -2105,90 +2104,6 @@ func (s *RetryLayerChannelStore) GetTeamMembersForChannel(channelID string) ([]s
|
||||
|
||||
}
|
||||
|
||||
func (s *RetryLayerChannelStore) GetTopChannelsForTeamSince(teamID string, userID string, since int64, offset int, limit int) (*model.TopChannelList, error) {
|
||||
|
||||
tries := 0
|
||||
for {
|
||||
result, err := s.ChannelStore.GetTopChannelsForTeamSince(teamID, userID, since, offset, limit)
|
||||
if err == nil {
|
||||
return result, nil
|
||||
}
|
||||
if !isRepeatableError(err) {
|
||||
return result, err
|
||||
}
|
||||
tries++
|
||||
if tries >= 3 {
|
||||
err = errors.Wrap(err, "giving up after 3 consecutive repeatable transaction failures")
|
||||
return result, err
|
||||
}
|
||||
timepkg.Sleep(100 * timepkg.Millisecond)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func (s *RetryLayerChannelStore) GetTopChannelsForUserSince(userID string, teamID string, since int64, offset int, limit int) (*model.TopChannelList, error) {
|
||||
|
||||
tries := 0
|
||||
for {
|
||||
result, err := s.ChannelStore.GetTopChannelsForUserSince(userID, teamID, since, offset, limit)
|
||||
if err == nil {
|
||||
return result, nil
|
||||
}
|
||||
if !isRepeatableError(err) {
|
||||
return result, err
|
||||
}
|
||||
tries++
|
||||
if tries >= 3 {
|
||||
err = errors.Wrap(err, "giving up after 3 consecutive repeatable transaction failures")
|
||||
return result, err
|
||||
}
|
||||
timepkg.Sleep(100 * timepkg.Millisecond)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func (s *RetryLayerChannelStore) GetTopInactiveChannelsForTeamSince(teamID string, userID string, since int64, offset int, limit int) (*model.TopInactiveChannelList, error) {
|
||||
|
||||
tries := 0
|
||||
for {
|
||||
result, err := s.ChannelStore.GetTopInactiveChannelsForTeamSince(teamID, userID, since, offset, limit)
|
||||
if err == nil {
|
||||
return result, nil
|
||||
}
|
||||
if !isRepeatableError(err) {
|
||||
return result, err
|
||||
}
|
||||
tries++
|
||||
if tries >= 3 {
|
||||
err = errors.Wrap(err, "giving up after 3 consecutive repeatable transaction failures")
|
||||
return result, err
|
||||
}
|
||||
timepkg.Sleep(100 * timepkg.Millisecond)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func (s *RetryLayerChannelStore) GetTopInactiveChannelsForUserSince(teamID string, userID string, since int64, offset int, limit int) (*model.TopInactiveChannelList, error) {
|
||||
|
||||
tries := 0
|
||||
for {
|
||||
result, err := s.ChannelStore.GetTopInactiveChannelsForUserSince(teamID, userID, since, offset, limit)
|
||||
if err == nil {
|
||||
return result, nil
|
||||
}
|
||||
if !isRepeatableError(err) {
|
||||
return result, err
|
||||
}
|
||||
tries++
|
||||
if tries >= 3 {
|
||||
err = errors.Wrap(err, "giving up after 3 consecutive repeatable transaction failures")
|
||||
return result, err
|
||||
}
|
||||
timepkg.Sleep(100 * timepkg.Millisecond)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func (s *RetryLayerChannelStore) GroupSyncedChannelCount() (int64, error) {
|
||||
|
||||
tries := 0
|
||||
@@ -2384,27 +2299,6 @@ func (s *RetryLayerChannelStore) PermanentDeleteMembersByUser(userID string) err
|
||||
|
||||
}
|
||||
|
||||
func (s *RetryLayerChannelStore) PostCountsByDuration(channelIDs []string, sinceUnixMillis int64, userID *string, duration model.PostCountGrouping, groupingLocation *time.Location) ([]*model.DurationPostCount, error) {
|
||||
|
||||
tries := 0
|
||||
for {
|
||||
result, err := s.ChannelStore.PostCountsByDuration(channelIDs, sinceUnixMillis, userID, duration, groupingLocation)
|
||||
if err == nil {
|
||||
return result, nil
|
||||
}
|
||||
if !isRepeatableError(err) {
|
||||
return result, err
|
||||
}
|
||||
tries++
|
||||
if tries >= 3 {
|
||||
err = errors.Wrap(err, "giving up after 3 consecutive repeatable transaction failures")
|
||||
return result, err
|
||||
}
|
||||
timepkg.Sleep(100 * timepkg.Millisecond)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func (s *RetryLayerChannelStore) RemoveAllDeactivatedMembers(channelID string) error {
|
||||
|
||||
tries := 0
|
||||
@@ -7313,27 +7207,6 @@ func (s *RetryLayerPostStore) GetSingle(id string, inclDeleted bool) (*model.Pos
|
||||
|
||||
}
|
||||
|
||||
func (s *RetryLayerPostStore) GetTopDMsForUserSince(userID string, since int64, offset int, limit int) (*model.TopDMList, error) {
|
||||
|
||||
tries := 0
|
||||
for {
|
||||
result, err := s.PostStore.GetTopDMsForUserSince(userID, since, offset, limit)
|
||||
if err == nil {
|
||||
return result, nil
|
||||
}
|
||||
if !isRepeatableError(err) {
|
||||
return result, err
|
||||
}
|
||||
tries++
|
||||
if tries >= 3 {
|
||||
err = errors.Wrap(err, "giving up after 3 consecutive repeatable transaction failures")
|
||||
return result, err
|
||||
}
|
||||
timepkg.Sleep(100 * timepkg.Millisecond)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func (s *RetryLayerPostStore) HasAutoResponsePostByUserSince(options model.GetPostsSinceOptions, userId string) (bool, error) {
|
||||
|
||||
tries := 0
|
||||
@@ -8348,48 +8221,6 @@ func (s *RetryLayerReactionStore) GetForPostSince(postId string, since int64, ex
|
||||
|
||||
}
|
||||
|
||||
func (s *RetryLayerReactionStore) GetTopForTeamSince(teamID string, userID string, since int64, offset int, limit int) (*model.TopReactionList, error) {
|
||||
|
||||
tries := 0
|
||||
for {
|
||||
result, err := s.ReactionStore.GetTopForTeamSince(teamID, userID, since, offset, limit)
|
||||
if err == nil {
|
||||
return result, nil
|
||||
}
|
||||
if !isRepeatableError(err) {
|
||||
return result, err
|
||||
}
|
||||
tries++
|
||||
if tries >= 3 {
|
||||
err = errors.Wrap(err, "giving up after 3 consecutive repeatable transaction failures")
|
||||
return result, err
|
||||
}
|
||||
timepkg.Sleep(100 * timepkg.Millisecond)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func (s *RetryLayerReactionStore) GetTopForUserSince(userID string, teamID string, since int64, offset int, limit int) (*model.TopReactionList, error) {
|
||||
|
||||
tries := 0
|
||||
for {
|
||||
result, err := s.ReactionStore.GetTopForUserSince(userID, teamID, since, offset, limit)
|
||||
if err == nil {
|
||||
return result, nil
|
||||
}
|
||||
if !isRepeatableError(err) {
|
||||
return result, err
|
||||
}
|
||||
tries++
|
||||
if tries >= 3 {
|
||||
err = errors.Wrap(err, "giving up after 3 consecutive repeatable transaction failures")
|
||||
return result, err
|
||||
}
|
||||
timepkg.Sleep(100 * timepkg.Millisecond)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func (s *RetryLayerReactionStore) PermanentDeleteBatch(endTime int64, limit int64) (int64, error) {
|
||||
|
||||
tries := 0
|
||||
@@ -11000,27 +10831,6 @@ func (s *RetryLayerTeamStore) GetMembersByIds(teamID string, userIds []string, r
|
||||
|
||||
}
|
||||
|
||||
func (s *RetryLayerTeamStore) GetNewTeamMembersSince(teamID string, since int64, offset int, limit int, showFullName bool) (*model.NewTeamMembersList, int64, error) {
|
||||
|
||||
tries := 0
|
||||
for {
|
||||
result, resultVar1, err := s.TeamStore.GetNewTeamMembersSince(teamID, since, offset, limit, showFullName)
|
||||
if err == nil {
|
||||
return result, resultVar1, nil
|
||||
}
|
||||
if !isRepeatableError(err) {
|
||||
return result, resultVar1, err
|
||||
}
|
||||
tries++
|
||||
if tries >= 3 {
|
||||
err = errors.Wrap(err, "giving up after 3 consecutive repeatable transaction failures")
|
||||
return result, resultVar1, err
|
||||
}
|
||||
timepkg.Sleep(100 * timepkg.Millisecond)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func (s *RetryLayerTeamStore) GetTeamMembersForExport(userID string) ([]*model.TeamMemberForExport, error) {
|
||||
|
||||
tries := 0
|
||||
@@ -11909,48 +11719,6 @@ func (s *RetryLayerThreadStore) GetThreadsForUser(userId string, teamID string,
|
||||
|
||||
}
|
||||
|
||||
func (s *RetryLayerThreadStore) GetTopThreadsForTeamSince(teamID string, userID string, since int64, offset int, limit int) (*model.TopThreadList, error) {
|
||||
|
||||
tries := 0
|
||||
for {
|
||||
result, err := s.ThreadStore.GetTopThreadsForTeamSince(teamID, userID, since, offset, limit)
|
||||
if err == nil {
|
||||
return result, nil
|
||||
}
|
||||
if !isRepeatableError(err) {
|
||||
return result, err
|
||||
}
|
||||
tries++
|
||||
if tries >= 3 {
|
||||
err = errors.Wrap(err, "giving up after 3 consecutive repeatable transaction failures")
|
||||
return result, err
|
||||
}
|
||||
timepkg.Sleep(100 * timepkg.Millisecond)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func (s *RetryLayerThreadStore) GetTopThreadsForUserSince(teamID string, userID string, since int64, offset int, limit int) (*model.TopThreadList, error) {
|
||||
|
||||
tries := 0
|
||||
for {
|
||||
result, err := s.ThreadStore.GetTopThreadsForUserSince(teamID, userID, since, offset, limit)
|
||||
if err == nil {
|
||||
return result, nil
|
||||
}
|
||||
if !isRepeatableError(err) {
|
||||
return result, err
|
||||
}
|
||||
tries++
|
||||
if tries >= 3 {
|
||||
err = errors.Wrap(err, "giving up after 3 consecutive repeatable transaction failures")
|
||||
return result, err
|
||||
}
|
||||
timepkg.Sleep(100 * timepkg.Millisecond)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func (s *RetryLayerThreadStore) GetTotalThreads(userId string, teamID string, opts model.GetUserThreadsOpts) (int64, error) {
|
||||
|
||||
tries := 0
|
||||
|
||||
@@ -4342,414 +4342,3 @@ func (s SqlChannelStore) GetTeamForChannel(channelID string) (*model.Team, error
|
||||
}
|
||||
return &team, nil
|
||||
}
|
||||
|
||||
// GetTopChannelsForTeamSince returns the filtered post counts of the following Channels sets:
|
||||
// a) those that are private channels in the given user's membership graph on the given team, and
|
||||
// b) those that are public channels in the given team.
|
||||
func (s SqlChannelStore) GetTopChannelsForTeamSince(teamID string, userID string, since int64, offset int, limit int) (*model.TopChannelList, error) {
|
||||
channels := make([]*model.TopChannel, 0)
|
||||
var args []any
|
||||
postgresPropQuery := `AND (Posts.Props ->> 'from_bot' IS NULL OR Posts.Props ->> 'from_bot' = 'false') AND (Posts.Props ->> 'from_webhook' IS NULL OR Posts.Props ->> 'from_webhook' = 'false') AND (Posts.Props ->> 'from_oauth_app' IS NULL OR Posts.Props ->> 'from_oauth_app' = 'false') AND (Posts.Props ->> 'from_plugin' IS NULL OR Posts.Props ->> 'from_plugin' = 'false')`
|
||||
mySqlPropsQuery := `AND (JSON_EXTRACT(Posts.Props, '$.from_bot') IS NULL OR JSON_EXTRACT(Posts.Props, '$.from_bot') = 'false') AND (JSON_EXTRACT(Posts.Props, '$.from_webhook') IS NULL OR JSON_EXTRACT(Posts.Props, '$.from_webhook') = 'false') AND (JSON_EXTRACT(Posts.Props, '$.from_plugin') IS NULL OR JSON_EXTRACT(Posts.Props, '$.from_plugin') = 'false') AND (JSON_EXTRACT(Posts.Props, '$.from_oauth_app') IS NULL OR JSON_EXTRACT(Posts.Props, '$.from_oauth_app') = 'false')`
|
||||
|
||||
query := `
|
||||
SELECT
|
||||
ID,
|
||||
Type,
|
||||
DisplayName,
|
||||
Name,
|
||||
TeamID,
|
||||
MessageCount
|
||||
FROM
|
||||
((SELECT
|
||||
Posts.ChannelId AS ID,
|
||||
'O' AS Type,
|
||||
PublicChannels.DisplayName AS DisplayName,
|
||||
PublicChannels.Name AS Name,
|
||||
PublicChannels.TeamId AS TeamID,
|
||||
count(Posts.Id) AS MessageCount,
|
||||
PublicChannels.DeleteAt AS DeleteAt
|
||||
FROM
|
||||
Posts
|
||||
LEFT JOIN PublicChannels on Posts.ChannelId = PublicChannels.Id
|
||||
WHERE
|
||||
Posts.DeleteAt = 0
|
||||
AND Posts.CreateAt > ?
|
||||
AND Posts.Type = ''`
|
||||
args = []any{since}
|
||||
|
||||
if s.DriverName() == model.DatabaseDriverMysql {
|
||||
query += mySqlPropsQuery
|
||||
} else if s.DriverName() == model.DatabaseDriverPostgres {
|
||||
query += postgresPropQuery
|
||||
}
|
||||
|
||||
query += `
|
||||
AND PublicChannels.TeamId = ?
|
||||
GROUP BY
|
||||
Posts.ChannelId,
|
||||
PublicChannels.DisplayName,
|
||||
PublicChannels.Name,
|
||||
PublicChannels.TeamId,
|
||||
PublicChannels.DeleteAt)
|
||||
UNION ALL
|
||||
(SELECT
|
||||
Posts.ChannelId AS ID,
|
||||
Channels.Type AS Type,
|
||||
Channels.DisplayName AS DisplayName,
|
||||
Channels.Name AS Name,
|
||||
Channels.TeamId AS TeamID,
|
||||
count(Posts.Id) AS MessageCount,
|
||||
Channels.DeleteAt AS DeleteAt
|
||||
FROM
|
||||
Posts
|
||||
LEFT JOIN Channels on Posts.ChannelId = Channels.Id
|
||||
LEFT JOIN ChannelMembers on Posts.ChannelId = ChannelMembers.ChannelId
|
||||
WHERE
|
||||
Posts.DeleteAt = 0
|
||||
AND Posts.CreateAt > ?
|
||||
AND Posts.Type = ''`
|
||||
args = append(args, teamID, since)
|
||||
|
||||
if s.DriverName() == model.DatabaseDriverMysql {
|
||||
query += mySqlPropsQuery
|
||||
} else if s.DriverName() == model.DatabaseDriverPostgres {
|
||||
query += postgresPropQuery
|
||||
}
|
||||
|
||||
query += `
|
||||
AND Channels.TeamId = ?
|
||||
AND Channels.Type = 'P'
|
||||
AND ChannelMembers.UserId = ?
|
||||
GROUP BY
|
||||
Posts.ChannelId,
|
||||
Channels.Type,
|
||||
Channels.DisplayName,
|
||||
Channels.Name,
|
||||
Channels.TeamId,
|
||||
Channels.DeleteAt)) AS A
|
||||
WHERE
|
||||
DeleteAt = 0
|
||||
ORDER BY
|
||||
MessageCount DESC,
|
||||
Name ASC
|
||||
LIMIT ?
|
||||
OFFSET ?`
|
||||
args = append(args, teamID, userID, limit+1, offset)
|
||||
|
||||
if err := s.GetReplicaX().Select(&channels, query, args...); err != nil {
|
||||
return nil, errors.Wrap(err, "failed to get top Channels")
|
||||
}
|
||||
|
||||
return model.GetTopChannelListWithPagination(channels, limit), nil
|
||||
}
|
||||
|
||||
// GetTopChannelsForUserSince returns the filtered post counts of channels with with posts created by the user
|
||||
// after the given timestamp within the given team (or across the workspace if no team is given). Excludes DM and GM channels.
|
||||
func (s SqlChannelStore) GetTopChannelsForUserSince(userID string, teamID string, since int64, offset int, limit int) (*model.TopChannelList, error) {
|
||||
channels := make([]*model.TopChannel, 0)
|
||||
var args []any
|
||||
var query string
|
||||
|
||||
var propsQuery string
|
||||
if s.DriverName() == model.DatabaseDriverMysql {
|
||||
propsQuery = `AND (JSON_EXTRACT(Posts.Props, '$.from_bot') IS NULL OR JSON_EXTRACT(Posts.Props, '$.from_bot') = 'false') AND (JSON_EXTRACT(Posts.Props, '$.from_webhook') IS NULL OR JSON_EXTRACT(Posts.Props, '$.from_webhook') = 'false') AND (JSON_EXTRACT(Posts.Props, '$.from_plugin') IS NULL OR JSON_EXTRACT(Posts.Props, '$.from_plugin') = 'false') AND (JSON_EXTRACT(Posts.Props, '$.from_oauth_app') IS NULL OR JSON_EXTRACT(Posts.Props, '$.from_oauth_app') = 'false')`
|
||||
} else if s.DriverName() == model.DatabaseDriverPostgres {
|
||||
propsQuery = `AND (Posts.Props ->> 'from_bot' IS NULL OR Posts.Props ->> 'from_bot' = 'false') AND (Posts.Props ->> 'from_webhook' IS NULL OR Posts.Props ->> 'from_webhook' = 'false') AND (Posts.Props ->> 'from_oauth_app' IS NULL OR Posts.Props ->> 'from_oauth_app' = 'false') AND (Posts.Props ->> 'from_plugin' IS NULL OR Posts.Props ->> 'from_plugin' = 'false')`
|
||||
}
|
||||
|
||||
query = `
|
||||
SELECT
|
||||
Posts.ChannelId AS ID,
|
||||
Channels.Type AS Type,
|
||||
Channels.DisplayName AS DisplayName,
|
||||
Channels.Name AS Name,
|
||||
Channels.TeamId AS TeamID,
|
||||
count(Posts.Id) AS MessageCount
|
||||
FROM
|
||||
Posts
|
||||
LEFT JOIN Channels on Posts.ChannelId = Channels.Id
|
||||
LEFT JOIN ChannelMembers on Posts.ChannelId = ChannelMembers.ChannelId
|
||||
WHERE
|
||||
Posts.DeleteAt = 0
|
||||
AND Posts.CreateAt > ?
|
||||
AND Posts.Type = ''
|
||||
AND Posts.UserID = ?
|
||||
AND Channels.DeleteAt = 0
|
||||
AND (Channels.Type = 'O' OR Channels.Type = 'P')
|
||||
AND ChannelMembers.UserId = ? `
|
||||
|
||||
query += propsQuery
|
||||
|
||||
args = []any{since, userID, userID}
|
||||
|
||||
if teamID != "" {
|
||||
query += `
|
||||
AND Channels.TeamID = ?`
|
||||
args = append(args, teamID)
|
||||
}
|
||||
|
||||
query += `
|
||||
Group By
|
||||
Posts.ChannelId,
|
||||
Channels.Type,
|
||||
Channels.DisplayName,
|
||||
Channels.Name,
|
||||
Channels.TeamId
|
||||
ORDER BY
|
||||
MessageCount DESC,
|
||||
Name ASC
|
||||
LIMIT ?
|
||||
OFFSET ?`
|
||||
args = append(args, limit+1, offset)
|
||||
|
||||
if err := s.GetReplicaX().Select(&channels, query, args...); err != nil {
|
||||
return nil, errors.Wrap(err, "failed to get top Channels")
|
||||
}
|
||||
|
||||
return model.GetTopChannelListWithPagination(channels, limit), nil
|
||||
}
|
||||
|
||||
// GetTopInactiveChannelsForTeamSince returns the filtered post counts of the following Channels sets:
|
||||
// a) those that are private channels in the given user's membership graph on the given team, and
|
||||
// b) those that are public channels in the given team.
|
||||
func (s SqlChannelStore) GetTopInactiveChannelsForTeamSince(teamID string, userID string, since int64, offset int, limit int) (*model.TopInactiveChannelList, error) {
|
||||
channels := make([]*model.TopInactiveChannel, 0)
|
||||
var args []any
|
||||
|
||||
query := `
|
||||
SELECT
|
||||
ID,
|
||||
Type,
|
||||
DisplayName,
|
||||
Name,
|
||||
MessageCount,
|
||||
LastActivityAt
|
||||
FROM
|
||||
((SELECT
|
||||
PublicChannels.Id AS ID,
|
||||
'O' AS Type,
|
||||
PublicChannels.DisplayName AS DisplayName,
|
||||
PublicChannels.Name AS Name,
|
||||
COALESCE(count(Posts.Id), 0) AS MessageCount,
|
||||
COALESCE(max(Posts.CreateAt), 0) AS LastActivityAt
|
||||
FROM
|
||||
PublicChannels
|
||||
LEFT JOIN Posts on Posts.ChannelId = PublicChannels.Id AND Posts.Type = '' AND Posts.CreateAt > ? AND Posts.DeleteAt = 0
|
||||
LEFT JOIN Channels on Channels.Id = PublicChannels.Id
|
||||
WHERE
|
||||
PublicChannels.TeamId = ?
|
||||
AND PublicChannels.DeleteAt = 0
|
||||
AND Channels.CreateAt < ?
|
||||
GROUP BY
|
||||
PublicChannels.Id,
|
||||
PublicChannels.DisplayName,
|
||||
PublicChannels.Name,
|
||||
PublicChannels.TeamId)
|
||||
UNION ALL
|
||||
(SELECT
|
||||
Channels.Id AS ID,
|
||||
Channels.Type AS Type,
|
||||
Channels.DisplayName AS DisplayName,
|
||||
Channels.Name AS Name,
|
||||
COALESCE(count(Posts.Id), 0) AS MessageCount,
|
||||
COALESCE(max(Posts.CreateAt), 0) AS LastActivityAt
|
||||
FROM
|
||||
Channels
|
||||
LEFT JOIN Posts on Posts.ChannelId = Channels.Id AND Posts.Type = '' AND Posts.CreateAt > ? AND Posts.DeleteAt = 0
|
||||
LEFT JOIN ChannelMembers on Channels.Id = ChannelMembers.ChannelId
|
||||
WHERE
|
||||
Channels.TeamId = ?
|
||||
AND Channels.CreateAt < ?
|
||||
AND Channels.Type = 'P'
|
||||
AND Channels.DeleteAt = 0
|
||||
AND ChannelMembers.UserId = ?
|
||||
GROUP BY
|
||||
Channels.Id,
|
||||
Channels.Type,
|
||||
Channels.DisplayName,
|
||||
Channels.Name)) AS A
|
||||
ORDER BY
|
||||
MessageCount ASC,
|
||||
Name ASC
|
||||
LIMIT ?
|
||||
OFFSET ?`
|
||||
args = append(args, since, teamID, since, since, teamID, since, userID, limit+1, offset)
|
||||
if err := s.GetReplicaX().Select(&channels, query, args...); err != nil {
|
||||
return nil, errors.Wrap(err, "failed to get top Channels")
|
||||
}
|
||||
|
||||
channels, err := postProcessTopInactiveChannels(s, channels)
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return model.GetTopInactiveChannelListWithPagination(channels, limit), nil
|
||||
}
|
||||
|
||||
// GetTopInactiveChannelsForUserSince returns the filtered post counts of channels with with posts created by the user
|
||||
// after the given timestamp within the given team (or across the workspace if no team is given). Excludes DM and GM channels.
|
||||
func (s SqlChannelStore) GetTopInactiveChannelsForUserSince(teamID string, userID string, since int64, offset int, limit int) (*model.TopInactiveChannelList, error) {
|
||||
channels := make([]*model.TopInactiveChannel, 0)
|
||||
var args []any
|
||||
var query string
|
||||
|
||||
query = `
|
||||
SELECT
|
||||
Channels.Id AS ID,
|
||||
Channels.Type AS Type,
|
||||
Channels.DisplayName AS DisplayName,
|
||||
Channels.Name AS Name,
|
||||
COALESCE(count(Posts.Id), 0) AS MessageCount,
|
||||
COALESCE(max(Posts.CreateAt), 0) AS LastActivityAt
|
||||
FROM
|
||||
Channels
|
||||
LEFT JOIN Posts on Posts.ChannelId = Channels.Id AND Posts.Type = '' AND Posts.CreateAt > ? AND Posts.DeleteAt = 0
|
||||
LEFT JOIN ChannelMembers on Channels.Id = ChannelMembers.ChannelId
|
||||
WHERE
|
||||
Channels.DeleteAt = 0
|
||||
AND Channels.CreateAt < ?
|
||||
AND (Channels.Type = 'O' OR Channels.Type = 'P')
|
||||
AND ChannelMembers.UserId = ? `
|
||||
|
||||
args = []any{since, since, userID}
|
||||
|
||||
if teamID != "" {
|
||||
query += `
|
||||
AND Channels.TeamID = ?`
|
||||
args = append(args, teamID)
|
||||
}
|
||||
|
||||
query += `
|
||||
Group By
|
||||
Channels.Id,
|
||||
Channels.Type,
|
||||
Channels.DisplayName,
|
||||
Channels.Name
|
||||
ORDER BY
|
||||
MessageCount ASC,
|
||||
Name ASC
|
||||
LIMIT ?
|
||||
OFFSET ?`
|
||||
args = append(args, limit+1, offset)
|
||||
|
||||
if err := s.GetReplicaX().Select(&channels, query, args...); err != nil {
|
||||
return nil, errors.Wrap(err, "failed to get top Inactive Channels")
|
||||
}
|
||||
|
||||
channels, err := postProcessTopInactiveChannels(s, channels)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return model.GetTopInactiveChannelListWithPagination(channels, limit), nil
|
||||
}
|
||||
|
||||
func postProcessTopInactiveChannels(s SqlChannelStore, channels []*model.TopInactiveChannel) ([]*model.TopInactiveChannel, error) {
|
||||
// query channel members for Ids
|
||||
var conditionalAggrSelector string
|
||||
if s.DriverName() == model.DatabaseDriverMysql {
|
||||
conditionalAggrSelector = "GROUP_CONCAT(UserId SEPARATOR ',') as UserIds"
|
||||
} else if s.DriverName() == model.DatabaseDriverPostgres {
|
||||
conditionalAggrSelector = "string_agg(UserId, ',') as UserIds"
|
||||
}
|
||||
|
||||
var channelIds []string
|
||||
for _, channel := range channels {
|
||||
channelIds = append(channelIds, channel.ID)
|
||||
}
|
||||
q := s.getQueryBuilder().Select("ChannelId", conditionalAggrSelector).From("ChannelMembers").
|
||||
Where(sq.Eq{
|
||||
"ChannelId": channelIds,
|
||||
}).GroupBy("ChannelId")
|
||||
|
||||
channelsUserIdsMap := make(map[string]string, len(channels))
|
||||
type ChannelUserIdsResult struct {
|
||||
ChannelId string
|
||||
UserIds string
|
||||
}
|
||||
|
||||
channelsUserIdsResultList := make([]ChannelUserIdsResult, len(channels))
|
||||
sql, args, err := q.ToSql()
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "failed to stringify squirrel query")
|
||||
}
|
||||
if err := s.GetReplicaX().Select(&channelsUserIdsResultList, sql, args...); err != nil {
|
||||
return nil, errors.Wrap(err, "failed to get top Inactive Channels users")
|
||||
}
|
||||
|
||||
for _, channelUserIds := range channelsUserIdsResultList {
|
||||
channelsUserIdsMap[channelUserIds.ChannelId] = channelUserIds.UserIds
|
||||
}
|
||||
for index, channel := range channels {
|
||||
userIds := channelsUserIdsMap[channel.ID]
|
||||
userIdsSlice := strings.Split(userIds, ",")
|
||||
|
||||
channels[index].Participants = userIdsSlice
|
||||
|
||||
// handle channels with 0 participants
|
||||
if len(userIdsSlice) == 1 && userIdsSlice[0] == "" {
|
||||
channels[index].Participants = make([]string, 0)
|
||||
}
|
||||
}
|
||||
return channels, nil
|
||||
}
|
||||
|
||||
func (s SqlChannelStore) PostCountsByDuration(channelIDs []string, sinceUnixMillis int64, userID *string, duration model.PostCountGrouping, atLocation *time.Location) ([]*model.DurationPostCount, error) {
|
||||
var unixSelect string
|
||||
var propsQuery string
|
||||
loc := atLocation.String()
|
||||
if loc == "Local" {
|
||||
loc = "UTC"
|
||||
}
|
||||
var format string
|
||||
if s.DriverName() == model.DatabaseDriverMysql {
|
||||
if duration == model.PostsByDay {
|
||||
format = `%Y-%m-%d`
|
||||
} else {
|
||||
format = `%Y-%m-%dT%H`
|
||||
}
|
||||
unixSelect = fmt.Sprintf(`DATE_FORMAT(
|
||||
COALESCE(
|
||||
CONVERT_TZ(FROM_UNIXTIME(Posts.CreateAt / 1000), 'GMT', '%s'),
|
||||
FROM_UNIXTIME(Posts.CreateAt / 1000)
|
||||
),
|
||||
'%s') AS duration`, loc, format)
|
||||
propsQuery = `(JSON_EXTRACT(Posts.Props, '$.from_bot') IS NULL OR JSON_EXTRACT(Posts.Props, '$.from_bot') = 'false') AND (JSON_EXTRACT(Posts.Props, '$.from_webhook') IS NULL OR JSON_EXTRACT(Posts.Props, '$.from_webhook') = 'false') AND (JSON_EXTRACT(Posts.Props, '$.from_plugin') IS NULL OR JSON_EXTRACT(Posts.Props, '$.from_plugin') = 'false') AND (JSON_EXTRACT(Posts.Props, '$.from_oauth_app') IS NULL OR JSON_EXTRACT(Posts.Props, '$.from_oauth_app') = 'false')`
|
||||
} else if s.DriverName() == model.DatabaseDriverPostgres {
|
||||
if duration == model.PostsByDay {
|
||||
format = "YYYY-MM-DD"
|
||||
} else {
|
||||
format = `YYYY-MM-DD"T"HH24`
|
||||
}
|
||||
unixSelect = fmt.Sprintf(`TO_CHAR(TO_TIMESTAMP(Posts.CreateAt / 1000) AT TIME ZONE '%s', '%s') AS duration`, loc, format)
|
||||
propsQuery = `(Posts.Props ->> 'from_bot' IS NULL OR Posts.Props ->> 'from_bot' = 'false') AND (Posts.Props ->> 'from_webhook' IS NULL OR Posts.Props ->> 'from_webhook' = 'false') AND (Posts.Props ->> 'from_oauth_app' IS NULL OR Posts.Props ->> 'from_oauth_app' = 'false') AND (Posts.Props ->> 'from_plugin' IS NULL OR Posts.Props ->> 'from_plugin' = 'false')`
|
||||
}
|
||||
query := sq.
|
||||
Select("Posts.ChannelId AS channelid", unixSelect, "count(Posts.Id) AS postcount").
|
||||
From("Posts").
|
||||
LeftJoin("Channels ON Posts.ChannelId = Channels.Id").
|
||||
Where(sq.And{
|
||||
sq.Eq{"Posts.DeleteAt": 0},
|
||||
sq.Gt{"Posts.CreateAt": sinceUnixMillis},
|
||||
sq.Eq{"Posts.Type": ""},
|
||||
sq.Eq{"Channels.Id": channelIDs},
|
||||
}).
|
||||
Where(propsQuery).
|
||||
GroupBy("channelid", "duration").
|
||||
OrderBy("channelid", "duration")
|
||||
if userID != nil && model.IsValidId(*userID) {
|
||||
query = query.Where(sq.And{sq.Eq{"Posts.UserId": *userID}})
|
||||
}
|
||||
queryString, args, err := query.ToSql()
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "failed to parse query")
|
||||
}
|
||||
dailyPostCounts := make([]*model.DurationPostCount, 0)
|
||||
if err := s.GetReplicaX().Select(&dailyPostCounts, queryString, args...); err != nil {
|
||||
return nil, errors.Wrap(err, "failed to get post counts by duration")
|
||||
}
|
||||
|
||||
return dailyPostCounts, nil
|
||||
}
|
||||
|
||||
@@ -3059,163 +3059,6 @@ func (s *SqlPostStore) updateThreadsFromPosts(transaction *sqlxTxWrapper, posts
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *SqlPostStore) GetTopDMsForUserSince(userID string, since int64, offset int, limit int) (*model.TopDMList, error) {
|
||||
var botsFilterExpr string
|
||||
/*
|
||||
Channel.Name is of the format userId1__userId2.
|
||||
Using this, self dms, and bot dms can be filtered.
|
||||
*/
|
||||
if s.DriverName() == model.DatabaseDriverPostgres {
|
||||
botsFilterExpr = `SPLIT_PART(Channels.Name, '__', 1) NOT IN (SELECT UserId FROM Bots)
|
||||
AND SPLIT_PART(Channels.Name, '__', 2) NOT IN (SELECT UserId FROM Bots)
|
||||
`
|
||||
} else if s.DriverName() == model.DatabaseDriverMysql {
|
||||
botsFilterExpr = `SUBSTRING_INDEX(Channels.Name, '__', 1) NOT IN (SELECT UserId FROM Bots)
|
||||
AND SUBSTRING_INDEX(Channels.Name, '__', -1) NOT IN (SELECT UserId FROM Bots)
|
||||
`
|
||||
}
|
||||
|
||||
channelSelector := s.getQueryBuilder().Select("Id", "TotalMsgCount").From("Channels").Join("ChannelMembers as cm on cm.ChannelId = Channels.Id").
|
||||
Where(sq.And{
|
||||
sq.Expr("Channels.Type = 'D'"),
|
||||
sq.Eq{"cm.UserId": userID},
|
||||
sq.NotEq{"Channels.Name": fmt.Sprintf("%s__%s", userID, userID)},
|
||||
sq.Expr(botsFilterExpr),
|
||||
})
|
||||
var aggregator string
|
||||
|
||||
if s.DriverName() == model.DatabaseDriverMysql {
|
||||
aggregator = "group_concat(distinct cm.UserId) as Participants"
|
||||
} else {
|
||||
aggregator = "string_agg(distinct cm.UserId, ',') as Participants"
|
||||
}
|
||||
|
||||
topDMsBuilder := s.getQueryBuilder().Select("count(p.Id) as MessageCount", aggregator, "vch.Id as ChannelId").FromSelect(channelSelector, "vch").
|
||||
Join("ChannelMembers as cm on cm.ChannelId = vch.Id").
|
||||
Join("Posts as p on p.ChannelId = vch.Id").
|
||||
Where(sq.And{
|
||||
sq.Gt{
|
||||
"p.UpdateAt": since,
|
||||
},
|
||||
sq.Eq{
|
||||
"p.DeleteAt": 0,
|
||||
},
|
||||
}).GroupBy("vch.id")
|
||||
|
||||
// following where clause filters out all archived DMs with "deleted" users, that has only 1 user-id in Participants column.
|
||||
archivedDMsFilter := s.getQueryBuilder().Select("MessageCount", "Participants", "ChannelId").FromSelect(topDMsBuilder, "top_dms").
|
||||
Where(sq.Expr("POSITION(',' IN Participants) > 0"))
|
||||
|
||||
archivedDMsFilter = archivedDMsFilter.OrderBy("MessageCount DESC").Limit(uint64(limit + 1)).Offset(uint64(offset))
|
||||
|
||||
topDMs := make([]*model.TopDM, 0)
|
||||
sql, args, err := archivedDMsFilter.ToSql()
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "GetTopDMsForUserSince_ToSql")
|
||||
}
|
||||
err = s.GetReplicaX().Select(&topDMs, sql, args...)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "failed to find top DMs for user-id: %s", userID)
|
||||
}
|
||||
|
||||
// fill SecondParticipant column
|
||||
topDMs, err = postProcessTopDMs(s, userID, topDMs, since)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return model.GetTopDMListWithPagination(topDMs, limit), nil
|
||||
}
|
||||
|
||||
func postProcessTopDMs(s *SqlPostStore, userID string, topDMs []*model.TopDM, since int64) ([]*model.TopDM, error) {
|
||||
var topDMsFiltered = []*model.TopDM{}
|
||||
var secondParticipantIds []string
|
||||
var channelIds []string
|
||||
|
||||
// identify second participant in a list of participants
|
||||
for _, topDM := range topDMs {
|
||||
participants := strings.Split(topDM.Participants, ",")
|
||||
var secondParticipantId string
|
||||
// divide message count by 2, because it's counted twice due to channel memberships being 2 for dms.
|
||||
topDM.MessageCount = topDM.MessageCount / 2
|
||||
if participants[0] == userID {
|
||||
secondParticipantId = participants[1]
|
||||
} else {
|
||||
secondParticipantId = participants[0]
|
||||
}
|
||||
secondParticipantIds = append(secondParticipantIds, secondParticipantId)
|
||||
channelIds = append(channelIds, topDM.ChannelId)
|
||||
}
|
||||
|
||||
// get user profiles
|
||||
users, err := s.User().GetProfileByIds(context.Background(), secondParticipantIds, &store.UserGetByIdsOpts{}, true)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "failed to get second participants' information")
|
||||
}
|
||||
|
||||
// get outgoing message count for userId
|
||||
outgoingMessagesQuery := s.getQueryBuilder().Select("ch.Id as ChannelId, count(p.Id) as MessageCount").From("Channels as ch").
|
||||
Join("Posts as p on p.ChannelId=ch.Id").Where(
|
||||
sq.And{
|
||||
sq.Gt{
|
||||
"p.UpdateAt": since,
|
||||
},
|
||||
sq.Eq{
|
||||
"p.DeleteAt": 0,
|
||||
},
|
||||
sq.Eq{
|
||||
"ch.Id": channelIds,
|
||||
},
|
||||
sq.Eq{
|
||||
"p.UserId": userID,
|
||||
},
|
||||
}).GroupBy("ch.Id")
|
||||
|
||||
outgoingMessages := make([]*model.OutgoingMessageQueryResult, 0)
|
||||
sql, args, err := outgoingMessagesQuery.ToSql()
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "GetTopDMsForUserSince_outgoingMessagesQuery_ToSql")
|
||||
}
|
||||
err = s.GetReplicaX().Select(&outgoingMessages, sql, args...)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "failed to find top DMs for user-id: %s", userID)
|
||||
}
|
||||
|
||||
// create map of channelId -> MessageCount
|
||||
outgoingMessagesMap := make(map[string]int)
|
||||
for _, outgoingMessage := range outgoingMessages {
|
||||
outgoingMessagesMap[outgoingMessage.ChannelId] = outgoingMessage.MessageCount
|
||||
}
|
||||
|
||||
// create map of userId -> User
|
||||
usersMap := make(map[string]*model.User)
|
||||
for _, user := range users {
|
||||
usersMap[user.Id] = user
|
||||
}
|
||||
|
||||
for index, topDM := range topDMs {
|
||||
if secondParticipantIds[index] == "-1" {
|
||||
return nil, errors.Wrapf(err, "failed to find second user for topDM: %s", userID)
|
||||
}
|
||||
user := usersMap[secondParticipantIds[index]]
|
||||
topDM.SecondParticipant = &model.TopDMInsightUserInformation{
|
||||
InsightUserInformation: model.InsightUserInformation{
|
||||
Id: user.Id,
|
||||
LastPictureUpdate: user.LastPictureUpdate,
|
||||
FirstName: user.FirstName,
|
||||
LastName: user.LastName,
|
||||
Username: user.Username,
|
||||
NickName: user.Nickname,
|
||||
},
|
||||
Position: user.Position,
|
||||
}
|
||||
|
||||
topDM.OutgoingMessageCount = int64(outgoingMessagesMap[topDM.ChannelId])
|
||||
topDMsFiltered = append(topDMsFiltered, topDM)
|
||||
}
|
||||
|
||||
return topDMsFiltered, nil
|
||||
}
|
||||
|
||||
func (s *SqlPostStore) SetPostReminder(reminder *model.PostReminder) error {
|
||||
transaction, err := s.GetMasterX().Beginx()
|
||||
if err != nil {
|
||||
|
||||
@@ -245,124 +245,6 @@ func (s *SqlReactionStore) PermanentDeleteBatch(endTime int64, limit int64) (int
|
||||
return rowsAffected, nil
|
||||
}
|
||||
|
||||
// GetTopForTeamSince returns the instance counts of the following Reactions sets:
|
||||
// a) those created by anyone in private channels in the given user's membership graph on the given team, and
|
||||
// b) those created by anyone in public channels on the given team.
|
||||
func (s *SqlReactionStore) GetTopForTeamSince(teamID string, userID string, since int64, offset int, limit int) (*model.TopReactionList, error) {
|
||||
reactions := make([]*model.TopReaction, 0)
|
||||
|
||||
query := `
|
||||
SELECT
|
||||
EmojiName,
|
||||
sum(EmojiCount) AS Count
|
||||
FROM ((
|
||||
SELECT
|
||||
EmojiName,
|
||||
count(EmojiName) AS EmojiCount,
|
||||
Reactions.DeleteAt AS DeleteAt,
|
||||
Reactions.CreateAt AS CreateAt
|
||||
FROM
|
||||
ChannelMembers
|
||||
INNER JOIN Channels ON ChannelMembers.ChannelId = Channels.Id
|
||||
INNER JOIN Reactions ON Channels.Id = Reactions.ChannelId
|
||||
WHERE
|
||||
ChannelMembers.UserId = ?
|
||||
AND Channels.Type = 'P'
|
||||
AND Channels.TeamId = ?
|
||||
GROUP BY
|
||||
Reactions.EmojiName,
|
||||
Reactions.DeleteAt,
|
||||
Reactions.CreateAt)
|
||||
UNION ALL (
|
||||
SELECT
|
||||
EmojiName,
|
||||
count(EmojiName) AS EmojiCount,
|
||||
Reactions.DeleteAt AS DeleteAt,
|
||||
Reactions.CreateAt AS CreateAt
|
||||
FROM
|
||||
Reactions
|
||||
INNER JOIN PublicChannels ON Reactions.ChannelId = PublicChannels.Id
|
||||
WHERE
|
||||
PublicChannels.TeamId = ?
|
||||
GROUP BY
|
||||
Reactions.EmojiName,
|
||||
Reactions.DeleteAt,
|
||||
Reactions.CreateAt)) AS A
|
||||
WHERE
|
||||
DeleteAt = 0
|
||||
AND CreateAt > ?
|
||||
GROUP BY
|
||||
EmojiName
|
||||
ORDER BY
|
||||
Count DESC,
|
||||
EmojiName ASC
|
||||
LIMIT ?
|
||||
OFFSET ?`
|
||||
|
||||
if err := s.GetReplicaX().Select(&reactions, query, userID, teamID, teamID, since, limit+1, offset); err != nil {
|
||||
return nil, errors.Wrap(err, "failed to get top Reactions")
|
||||
}
|
||||
|
||||
return model.GetTopReactionListWithPagination(reactions, limit), nil
|
||||
}
|
||||
|
||||
// GetTopForUserSince returns the instance counts of the following Reactions sets:
|
||||
// a) those created by the given user in any channel type on the given team (across the workspace if no team is given), and
|
||||
// b) those created by the given user in DM or group channels.
|
||||
func (s *SqlReactionStore) GetTopForUserSince(userID string, teamID string, since int64, offset int, limit int) (*model.TopReactionList, error) {
|
||||
reactions := make([]*model.TopReaction, 0)
|
||||
var args []any
|
||||
var query string
|
||||
|
||||
if teamID != "" {
|
||||
query = `
|
||||
SELECT
|
||||
EmojiName,
|
||||
count(EmojiName) AS Count
|
||||
FROM
|
||||
Reactions
|
||||
INNER JOIN Channels ON Channels.Id = Reactions.ChannelId
|
||||
WHERE
|
||||
Reactions.DeleteAt = 0
|
||||
AND Reactions.UserId = ?
|
||||
AND (Channels.TeamId = ? OR Channels.Type = 'D' OR Channels.Type = 'G')
|
||||
AND Reactions.CreateAt > ?
|
||||
GROUP BY
|
||||
EmojiName
|
||||
ORDER BY
|
||||
Count DESC,
|
||||
EmojiName ASC
|
||||
LIMIT ?
|
||||
OFFSET ?`
|
||||
args = []any{userID, teamID, since, limit + 1, offset}
|
||||
} else {
|
||||
query = `
|
||||
SELECT
|
||||
EmojiName,
|
||||
count(EmojiName) AS Count
|
||||
FROM
|
||||
Reactions
|
||||
WHERE
|
||||
Reactions.DeleteAt = 0
|
||||
AND Reactions.UserId = ?
|
||||
AND Reactions.CreateAt > ?
|
||||
GROUP BY
|
||||
Reactions.EmojiName
|
||||
ORDER BY
|
||||
Count DESC,
|
||||
EmojiName ASC
|
||||
LIMIT ?
|
||||
OFFSET ?`
|
||||
args = []any{userID, since, limit + 1, offset}
|
||||
}
|
||||
|
||||
if err := s.GetReplicaX().Select(&reactions, query, args...); err != nil {
|
||||
return nil, errors.Wrap(err, "failed to get top Reactions")
|
||||
}
|
||||
|
||||
return model.GetTopReactionListWithPagination(reactions, limit), nil
|
||||
}
|
||||
|
||||
func (s *SqlReactionStore) saveReactionAndUpdatePost(transaction *sqlxTxWrapper, reaction *model.Reaction) error {
|
||||
reaction.DeleteAt = 0
|
||||
|
||||
|
||||
@@ -1652,46 +1652,3 @@ func (s SqlTeamStore) GroupSyncedTeamCount() (int64, error) {
|
||||
|
||||
return count, nil
|
||||
}
|
||||
|
||||
func (s SqlTeamStore) GetNewTeamMembersSince(teamID string, since int64, offset int, limit int, showFullName bool) (*model.NewTeamMembersList, int64, error) {
|
||||
builderF := func(selectClause string) sq.SelectBuilder {
|
||||
return s.getQueryBuilder().
|
||||
Select(selectClause).
|
||||
From("TeamMembers").
|
||||
Join("Users ON Users.id = TeamMembers.userid").
|
||||
LeftJoin("Bots ON Bots.userid = Users.id").
|
||||
Where(sq.GtOrEq{"TeamMembers.createat": since}).
|
||||
Where(sq.Eq{"TeamMembers.deleteat": 0, "teamid": teamID, "Users.deleteat": 0, "Bots.userid": nil})
|
||||
}
|
||||
|
||||
countBuilder := builderF("count(*)")
|
||||
query, args, err := countBuilder.ToSql()
|
||||
if err != nil {
|
||||
return nil, 0, errors.Wrap(err, "team_tosql")
|
||||
}
|
||||
var totalCount int64
|
||||
err = s.GetReplicaX().Get(&totalCount, query, args...)
|
||||
if err != nil {
|
||||
return nil, 0, errors.Wrap(err, "failed to count team members since")
|
||||
}
|
||||
|
||||
selectClause := "Users.Id, Users.Username, Users.Position, Users.LastPictureUpdate, TeamMembers.CreateAt, Users.Nickname"
|
||||
if showFullName {
|
||||
selectClause += ", Users.FirstName, Users.LastName"
|
||||
}
|
||||
|
||||
newTeamMembersBuilder := builderF(selectClause).
|
||||
Limit(uint64(limit + 1)).
|
||||
Offset(uint64(offset))
|
||||
query, args, err = newTeamMembersBuilder.ToSql()
|
||||
if err != nil {
|
||||
return nil, 0, errors.Wrap(err, "team_tosql")
|
||||
}
|
||||
var ntms []*model.NewTeamMember
|
||||
err = s.GetReplicaX().Select(&ntms, query, args...)
|
||||
if err != nil {
|
||||
return nil, 0, errors.Wrap(err, "failed to get team members since")
|
||||
}
|
||||
|
||||
return model.GetNewTeamMembersListWithPagination(ntms, limit), totalCount, nil
|
||||
}
|
||||
|
||||
@@ -1021,209 +1021,3 @@ func (s *SqlThreadStore) GetThreadUnreadReplyCount(threadMembership *model.Threa
|
||||
|
||||
return unreadReplies, nil
|
||||
}
|
||||
|
||||
// Top threads in all public channels and private channels userID is a member of. Returns a list of threads ranked by interactions.
|
||||
func (s *SqlThreadStore) GetTopThreadsForTeamSince(teamID string, userID string, since int64, offset int, limit int) (*model.TopThreadList, error) {
|
||||
var args []any
|
||||
query := `select
|
||||
threads_list.PostId,
|
||||
threads_list.ReplyCount,
|
||||
threads_list.ChannelId,
|
||||
threads_list.DisplayName,
|
||||
threads_list.Name,
|
||||
threads_list.Participants,
|
||||
p.UserId
|
||||
from((
|
||||
SELECT
|
||||
t.PostId,
|
||||
t.ReplyCount,
|
||||
t.ChannelId,
|
||||
t.Participants,
|
||||
c.DisplayName,
|
||||
c.Name
|
||||
FROM
|
||||
Threads t
|
||||
LEFT JOIN PublicChannels c ON t.ChannelId = c.Id
|
||||
WHERE
|
||||
t.threaddeleteat IS NULL
|
||||
AND t.LastReplyAt > ?
|
||||
AND c.TeamId = ?
|
||||
GROUP BY
|
||||
t.PostId,
|
||||
c.DisplayName,
|
||||
c.Name,
|
||||
t.Participants
|
||||
)
|
||||
UNION
|
||||
ALL (
|
||||
SELECT
|
||||
t.PostId,
|
||||
t.ReplyCount,
|
||||
t.ChannelId,
|
||||
t.Participants,
|
||||
c.DisplayName,
|
||||
c.Name
|
||||
FROM
|
||||
Threads t
|
||||
LEFT JOIN ChannelMembers cm ON t.ChannelId = cm.ChannelId
|
||||
LEFT JOIN Channels c ON t.ChannelId = c.Id
|
||||
WHERE
|
||||
t.threaddeleteat IS NULL
|
||||
AND cm.UserId = ?
|
||||
AND c.Type = 'P'
|
||||
AND c.TeamId = ?
|
||||
AND t.LastReplyAt > ?
|
||||
GROUP BY
|
||||
t.PostId,
|
||||
c.DisplayName,
|
||||
c.Name,
|
||||
t.Participants
|
||||
)) as threads_list
|
||||
LEFT JOIN Posts as p on p.Id = threads_list.PostId
|
||||
ORDER BY ReplyCount DESC
|
||||
limit ? offset ?`
|
||||
|
||||
args = append(args, since, teamID, userID, teamID, since, limit+1, offset)
|
||||
|
||||
topThreads := make([]*model.TopThread, 0)
|
||||
err := s.GetReplicaX().Select(&topThreads, query, args...)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "failed to get top threads=%s", teamID)
|
||||
}
|
||||
topThreads, err = postProcessTopThreads(topThreads, s, teamID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return model.GetTopThreadListWithPagination(topThreads, limit), nil
|
||||
}
|
||||
|
||||
func (s *SqlThreadStore) GetTopThreadsForUserSince(teamID string, userID string, since int64, offset int, limit int) (*model.TopThreadList, error) {
|
||||
var args []any
|
||||
|
||||
// gets all threads within the team which user follows.
|
||||
query := `select
|
||||
threads_list.PostId,
|
||||
threads_list.ReplyCount,
|
||||
threads_list.ChannelId,
|
||||
threads_list.DisplayName,
|
||||
threads_list.Name,
|
||||
threads_list.Participants,
|
||||
p.UserId
|
||||
from((
|
||||
SELECT
|
||||
t.PostId,
|
||||
t.ReplyCount,
|
||||
t.ChannelId,
|
||||
t.Participants,
|
||||
c.DisplayName,
|
||||
c.Name
|
||||
FROM
|
||||
Threads t
|
||||
LEFT JOIN PublicChannels c ON t.ChannelId = c.Id
|
||||
LEFT JOIN ThreadMemberships as tm on t.PostId = tm.PostId
|
||||
WHERE
|
||||
t.threaddeleteat IS NULL
|
||||
AND t.LastReplyAt > ?
|
||||
AND c.TeamId = ?
|
||||
AND tm.UserId = ?
|
||||
AND tm.Following = TRUE
|
||||
GROUP BY
|
||||
t.PostId,
|
||||
c.DisplayName,
|
||||
c.Name,
|
||||
t.Participants
|
||||
)
|
||||
UNION
|
||||
ALL (
|
||||
SELECT
|
||||
t.PostId,
|
||||
t.ReplyCount,
|
||||
t.ChannelId,
|
||||
t.Participants,
|
||||
c.DisplayName,
|
||||
c.Name
|
||||
FROM
|
||||
Threads t
|
||||
LEFT JOIN ChannelMembers cm ON t.ChannelId = cm.ChannelId
|
||||
LEFT JOIN Channels c ON t.ChannelId = c.Id
|
||||
LEFT JOIN ThreadMemberships as tm on t.PostId = tm.PostId
|
||||
WHERE
|
||||
cm.UserId = ?
|
||||
AND c.Type = 'P'
|
||||
AND c.TeamId = ?
|
||||
AND t.threaddeleteat IS NULL
|
||||
AND t.LastReplyAt > ?
|
||||
AND tm.UserId = ?
|
||||
AND tm.Following = TRUE
|
||||
GROUP BY
|
||||
t.PostId,
|
||||
c.DisplayName,
|
||||
c.Name,
|
||||
t.Participants
|
||||
)) as threads_list
|
||||
LEFT JOIN Posts as p on p.Id = threads_list.PostId
|
||||
ORDER BY ReplyCount DESC
|
||||
limit ? offset ?`
|
||||
|
||||
args = append(args, since, teamID, userID, userID, teamID, since, userID, limit+1, offset)
|
||||
|
||||
topThreads := make([]*model.TopThread, 0)
|
||||
err := s.GetReplicaX().Select(&topThreads, query, args...)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "failed to get top threads=%s", teamID)
|
||||
}
|
||||
topThreads, err = postProcessTopThreads(topThreads, s, teamID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return model.GetTopThreadListWithPagination(topThreads, limit), nil
|
||||
}
|
||||
|
||||
func userContains(userIDs []string, searchedUserID string) bool {
|
||||
for _, userID := range userIDs {
|
||||
if userID == searchedUserID {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func postProcessTopThreads(topThreads []*model.TopThread, s *SqlThreadStore, teamID string) ([]*model.TopThread, error) {
|
||||
// create list of userIDs
|
||||
var userIDs []string
|
||||
for _, topThread := range topThreads {
|
||||
userID := topThread.UserId
|
||||
if !userContains(userIDs, userID) {
|
||||
userIDs = append(userIDs, userID)
|
||||
}
|
||||
}
|
||||
|
||||
usersMap := map[string]*model.User{}
|
||||
|
||||
users, err := s.User().GetProfileByIds(context.Background(), userIDs, &store.UserGetByIdsOpts{}, true)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "failed to get users for top threads in team=%s", teamID)
|
||||
}
|
||||
for _, user := range users {
|
||||
usersMap[user.Id] = user
|
||||
}
|
||||
|
||||
// resolve user, root post for each top thread
|
||||
for _, topThread := range topThreads {
|
||||
postCreator := usersMap[topThread.UserId]
|
||||
topThread.UserInformation = &model.InsightUserInformation{
|
||||
Id: postCreator.Id,
|
||||
LastPictureUpdate: postCreator.LastPictureUpdate,
|
||||
FirstName: postCreator.FirstName,
|
||||
LastName: postCreator.LastName,
|
||||
Username: postCreator.Username,
|
||||
NickName: postCreator.Nickname,
|
||||
}
|
||||
post, err := s.Post().GetSingle(topThread.PostId, false)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "failed to get extended post for post id=%s", topThread.PostId)
|
||||
}
|
||||
topThread.Post = post
|
||||
}
|
||||
return topThreads, nil
|
||||
}
|
||||
|
||||
@@ -170,8 +170,6 @@ type TeamStore interface {
|
||||
// GetCommonTeamIDsForTwoUsers returns the intersection of all the teams to which the specified
|
||||
// users belong.
|
||||
GetCommonTeamIDsForTwoUsers(userID, otherUserID string) ([]string, error)
|
||||
|
||||
GetNewTeamMembersSince(teamID string, since int64, offset int, limit int, showFullName bool) (*model.NewTeamMembersList, int64, error)
|
||||
}
|
||||
|
||||
type ChannelStore interface {
|
||||
@@ -300,15 +298,6 @@ type ChannelStore interface {
|
||||
SetShared(channelId string, shared bool) error
|
||||
// GetTeamForChannel returns the team for a given channelID.
|
||||
GetTeamForChannel(channelID string) (*model.Team, error)
|
||||
|
||||
// Insights - channels
|
||||
GetTopChannelsForTeamSince(teamID string, userID string, since int64, offset int, limit int) (*model.TopChannelList, error)
|
||||
GetTopChannelsForUserSince(userID string, teamID string, since int64, offset int, limit int) (*model.TopChannelList, error)
|
||||
PostCountsByDuration(channelIDs []string, sinceUnixMillis int64, userID *string, duration model.PostCountGrouping, groupingLocation *time.Location) ([]*model.DurationPostCount, error)
|
||||
|
||||
// Insights - inactive channels
|
||||
GetTopInactiveChannelsForTeamSince(teamID string, userID string, since int64, offset int, limit int) (*model.TopInactiveChannelList, error)
|
||||
GetTopInactiveChannelsForUserSince(teamID string, userID string, since int64, offset int, limit int) (*model.TopInactiveChannelList, error)
|
||||
}
|
||||
|
||||
type ChannelMemberHistoryStore interface {
|
||||
@@ -347,10 +336,6 @@ type ThreadStore interface {
|
||||
DeleteOrphanedRows(limit int) (deleted int64, err error)
|
||||
GetThreadUnreadReplyCount(threadMembership *model.ThreadMembership) (int64, error)
|
||||
DeleteMembershipsForChannel(userID, channelID string) error
|
||||
|
||||
// Insights - threads
|
||||
GetTopThreadsForTeamSince(teamID string, userID string, since int64, offset int, limit int) (*model.TopThreadList, error)
|
||||
GetTopThreadsForUserSince(teamID string, userID string, since int64, offset int, limit int) (*model.TopThreadList, error)
|
||||
}
|
||||
|
||||
type PostStore interface {
|
||||
@@ -404,9 +389,6 @@ type PostStore interface {
|
||||
GetPostReminderMetadata(postID string) (*PostReminderMetadata, error)
|
||||
// GetNthRecentPostTime returns the CreateAt time of the nth most recent post.
|
||||
GetNthRecentPostTime(n int64) (int64, error)
|
||||
|
||||
// Insights - top DMs
|
||||
GetTopDMsForUserSince(userID string, since int64, offset int, limit int) (*model.TopDMList, error)
|
||||
}
|
||||
|
||||
type UserStore interface {
|
||||
@@ -727,8 +709,6 @@ type ReactionStore interface {
|
||||
BulkGetForPosts(postIds []string) ([]*model.Reaction, error)
|
||||
DeleteOrphanedRows(limit int) (int64, error)
|
||||
PermanentDeleteBatch(endTime int64, limit int64) (int64, error)
|
||||
GetTopForTeamSince(teamID string, userID string, since int64, offset int, limit int) (*model.TopReactionList, error)
|
||||
GetTopForUserSince(userID string, teamID string, since int64, offset int, limit int) (*model.TopReactionList, error)
|
||||
}
|
||||
|
||||
type JobStore interface {
|
||||
|
||||
@@ -149,8 +149,6 @@ func TestChannelStore(t *testing.T, ss store.Store, s SqlStore) {
|
||||
t.Run("UpdateSidebarChannelsByPreferences", func(t *testing.T) { testUpdateSidebarChannelsByPreferences(t, ss) })
|
||||
t.Run("SetShared", func(t *testing.T) { testSetShared(t, ss) })
|
||||
t.Run("GetTeamForChannel", func(t *testing.T) { testGetTeamForChannel(t, ss) })
|
||||
t.Run("PostCountsByDuration", func(t *testing.T) { testChannelPostCountsByDuration(t, ss) })
|
||||
t.Run("GetTopInactiveChannels", func(t *testing.T) { testGetTopInactiveChannels(t, ss) })
|
||||
}
|
||||
|
||||
func testChannelStoreSave(t *testing.T, ss store.Store) {
|
||||
@@ -8067,235 +8065,3 @@ func testGetTeamForChannel(t *testing.T, ss store.Store) {
|
||||
var nfErr *store.ErrNotFound
|
||||
require.True(t, errors.As(err, &nfErr))
|
||||
}
|
||||
|
||||
func testChannelPostCountsByDuration(t *testing.T, ss store.Store) {
|
||||
team, err := ss.Team().Save(&model.Team{
|
||||
Name: model.NewId(),
|
||||
DisplayName: "DisplayName",
|
||||
Email: MakeEmail(),
|
||||
Type: model.TeamOpen,
|
||||
})
|
||||
require.NoError(t, err)
|
||||
defer func() { ss.Team().PermanentDelete(team.Id) }()
|
||||
|
||||
channel := &model.Channel{
|
||||
TeamId: team.Id,
|
||||
DisplayName: "test_share_flag",
|
||||
Name: "test_share_flag",
|
||||
Type: model.ChannelTypeOpen,
|
||||
}
|
||||
channelSaved, err := ss.Channel().Save(channel, 999)
|
||||
require.NoError(t, err)
|
||||
defer func() { ss.Channel().PermanentDelete(channelSaved.Id) }()
|
||||
|
||||
userID := model.NewId()
|
||||
_, err = ss.Post().Save(&model.Post{
|
||||
UserId: userID,
|
||||
ChannelId: channel.Id,
|
||||
Message: "test",
|
||||
})
|
||||
require.NoError(t, err)
|
||||
|
||||
_, err = ss.Post().Save(&model.Post{
|
||||
UserId: userID,
|
||||
ChannelId: channel.Id,
|
||||
Message: "test",
|
||||
Props: model.StringInterface{
|
||||
"from_bot": true,
|
||||
},
|
||||
})
|
||||
require.NoError(t, err)
|
||||
|
||||
_, err = ss.Post().Save(&model.Post{
|
||||
UserId: userID,
|
||||
ChannelId: channel.Id,
|
||||
Message: "test",
|
||||
Props: model.StringInterface{
|
||||
"from_webhook": true,
|
||||
},
|
||||
})
|
||||
require.NoError(t, err)
|
||||
|
||||
dpc, err := ss.Channel().PostCountsByDuration([]string{channelSaved.Id}, 0, &userID, model.PostsByDay, time.Now().Location())
|
||||
require.NoError(t, err)
|
||||
require.Len(t, dpc, 1)
|
||||
require.Equal(t, channel.Id, dpc[0].ChannelID)
|
||||
require.Equal(t, 1, dpc[0].PostCount)
|
||||
}
|
||||
|
||||
func testGetTopInactiveChannels(t *testing.T, ss store.Store) {
|
||||
team, err := ss.Team().Save(&model.Team{
|
||||
Name: model.NewId(),
|
||||
DisplayName: "DisplayName",
|
||||
Email: MakeEmail(),
|
||||
Type: model.TeamOpen,
|
||||
})
|
||||
require.NoError(t, err)
|
||||
defer func() { ss.Team().PermanentDelete(team.Id) }()
|
||||
|
||||
channelPublic0 := &model.Channel{
|
||||
TeamId: team.Id,
|
||||
DisplayName: "test_share_flag asdf",
|
||||
Name: "test_share_flag_public0",
|
||||
Type: model.ChannelTypeOpen,
|
||||
CreateAt: 1,
|
||||
}
|
||||
|
||||
channelSaved0, err := ss.Channel().Save(channelPublic0, 999)
|
||||
require.NoError(t, err)
|
||||
defer func() { ss.Channel().PermanentDelete(channelSaved0.Id) }()
|
||||
|
||||
channelPublic1 := &model.Channel{
|
||||
TeamId: team.Id,
|
||||
DisplayName: "test_share_flag",
|
||||
Name: "test_share_flag",
|
||||
Type: model.ChannelTypeOpen,
|
||||
CreateAt: 1,
|
||||
}
|
||||
|
||||
channelSaved1, err := ss.Channel().Save(channelPublic1, 999)
|
||||
require.NoError(t, err)
|
||||
defer func() { ss.Channel().PermanentDelete(channelSaved1.Id) }()
|
||||
|
||||
// create private channel
|
||||
c3 := model.Channel{}
|
||||
c3.TeamId = team.Id
|
||||
c3.DisplayName = "Channel3" + model.NewId()
|
||||
c3.Name = NewTestId()
|
||||
c3.Type = model.ChannelTypePrivate
|
||||
c3.CreateAt = 1
|
||||
channelPrivate, nErr := ss.Channel().Save(&c3, -1)
|
||||
require.NoError(t, nErr)
|
||||
|
||||
// create private channel with post
|
||||
c3NoPost := model.Channel{}
|
||||
c3NoPost.TeamId = team.Id
|
||||
c3NoPost.DisplayName = "Channel3" + model.NewId()
|
||||
c3NoPost.Name = NewTestId()
|
||||
c3NoPost.Type = model.ChannelTypePrivate
|
||||
c3NoPost.CreateAt = 1
|
||||
channelPrivateNoPost, nErr := ss.Channel().Save(&c3NoPost, -1)
|
||||
require.NoError(t, nErr)
|
||||
|
||||
// create dm channel
|
||||
u1 := model.User{}
|
||||
u1.Email = MakeEmail()
|
||||
u1.Nickname = model.NewId()
|
||||
_, err = ss.User().Save(&u1)
|
||||
require.NoError(t, err)
|
||||
|
||||
u2 := model.User{}
|
||||
u2.Email = MakeEmail()
|
||||
u2.Nickname = model.NewId()
|
||||
_, err = ss.User().Save(&u2)
|
||||
require.NoError(t, err)
|
||||
|
||||
uBot := model.User{Id: model.NewId()}
|
||||
_, nErr = ss.Channel().CreateDirectChannel(&u1, &u2)
|
||||
require.NoError(t, nErr)
|
||||
|
||||
// add u1, u2 to channels
|
||||
|
||||
cm1 := &model.ChannelMember{ChannelId: channelPrivate.Id, UserId: u1.Id, NotifyProps: model.GetDefaultChannelNotifyProps()}
|
||||
_, err = ss.Channel().SaveMember(cm1)
|
||||
require.NoError(t, err)
|
||||
cm1NoPost := &model.ChannelMember{ChannelId: channelPrivateNoPost.Id, UserId: u1.Id, NotifyProps: model.GetDefaultChannelNotifyProps()}
|
||||
_, err = ss.Channel().SaveMember(cm1NoPost)
|
||||
require.NoError(t, err)
|
||||
cm1Public := &model.ChannelMember{ChannelId: channelPublic1.Id, UserId: u1.Id, NotifyProps: model.GetDefaultChannelNotifyProps()}
|
||||
_, err = ss.Channel().SaveMember(cm1Public)
|
||||
require.NoError(t, err)
|
||||
cm2 := &model.ChannelMember{ChannelId: channelPublic0.Id, UserId: u2.Id, NotifyProps: model.GetDefaultChannelNotifyProps()}
|
||||
_, err = ss.Channel().SaveMember(cm2)
|
||||
require.NoError(t, err)
|
||||
cmBot := &model.ChannelMember{ChannelId: channelPublic0.Id, UserId: uBot.Id, NotifyProps: model.GetDefaultChannelNotifyProps()}
|
||||
_, err = ss.Channel().SaveMember(cmBot)
|
||||
require.NoError(t, err)
|
||||
|
||||
_, err = ss.Post().Save(&model.Post{
|
||||
UserId: u1.Id,
|
||||
ChannelId: channelPrivate.Id,
|
||||
Message: "test",
|
||||
})
|
||||
require.NoError(t, err)
|
||||
|
||||
_, err = ss.Post().Save(&model.Post{
|
||||
UserId: u1.Id,
|
||||
ChannelId: channelPrivate.Id,
|
||||
Message: "test1",
|
||||
})
|
||||
require.NoError(t, err)
|
||||
|
||||
// create posts in channel public 0
|
||||
postToCheckLastUpdateAt, err := ss.Post().Save(&model.Post{
|
||||
UserId: u2.Id,
|
||||
ChannelId: channelSaved0.Id,
|
||||
Message: "test",
|
||||
})
|
||||
require.NoError(t, err)
|
||||
|
||||
_, err = ss.Post().Save(&model.Post{
|
||||
UserId: model.NewId(),
|
||||
ChannelId: channelPublic1.Id,
|
||||
Message: "test",
|
||||
Props: model.StringInterface{
|
||||
"from_bot": true,
|
||||
},
|
||||
})
|
||||
require.NoError(t, err)
|
||||
|
||||
// create posts in channel public 1
|
||||
for i := 0; i < 3; i++ {
|
||||
_, err = ss.Post().Save(&model.Post{
|
||||
UserId: model.NewId(),
|
||||
ChannelId: channelPublic1.Id,
|
||||
Message: "test",
|
||||
})
|
||||
require.NoError(t, err)
|
||||
}
|
||||
|
||||
// for u1
|
||||
t.Run("top inactive channels for team - u1 ", func(t *testing.T) {
|
||||
topInactiveChannels, err := ss.Channel().GetTopInactiveChannelsForTeamSince(team.Id, u1.Id, 2, 0, 10)
|
||||
require.NoError(t, err)
|
||||
require.Len(t, topInactiveChannels.Items, 4)
|
||||
require.Equal(t, topInactiveChannels.Items[0].ID, channelPrivateNoPost.Id)
|
||||
require.Equal(t, topInactiveChannels.Items[1].ID, channelSaved0.Id)
|
||||
require.Equal(t, topInactiveChannels.Items[1].LastActivityAt, postToCheckLastUpdateAt.CreateAt)
|
||||
require.Equal(t, topInactiveChannels.Items[2].ID, channelPrivate.Id)
|
||||
require.Equal(t, topInactiveChannels.Items[3].ID, channelPublic1.Id)
|
||||
// test bot posts are counted
|
||||
require.Equal(t, topInactiveChannels.Items[3].MessageCount, int64(4))
|
||||
|
||||
// participants
|
||||
require.Equal(t, topInactiveChannels.Items[2].Participants[0], u1.Id)
|
||||
require.Equal(t, topInactiveChannels.Items[3].Participants[0], u1.Id)
|
||||
})
|
||||
|
||||
t.Run("top inactive channels for user - u1 ", func(t *testing.T) {
|
||||
topInactiveChannels, err := ss.Channel().GetTopInactiveChannelsForUserSince(team.Id, u1.Id, 2, 0, 10)
|
||||
require.NoError(t, err)
|
||||
require.Len(t, topInactiveChannels.Items, 3)
|
||||
require.Equal(t, topInactiveChannels.Items[0].ID, channelPrivateNoPost.Id)
|
||||
require.Equal(t, topInactiveChannels.Items[1].ID, channelPrivate.Id)
|
||||
require.Equal(t, topInactiveChannels.Items[2].ID, channelPublic1.Id)
|
||||
})
|
||||
|
||||
// for u2
|
||||
t.Run("top inactive channels for team - u2 ", func(t *testing.T) {
|
||||
topInactiveChannels, err := ss.Channel().GetTopInactiveChannelsForTeamSince(team.Id, u2.Id, 2, 0, 10)
|
||||
require.NoError(t, err)
|
||||
require.Len(t, topInactiveChannels.Items, 2)
|
||||
require.Equal(t, topInactiveChannels.Items[0].ID, channelSaved0.Id)
|
||||
require.Equal(t, topInactiveChannels.Items[0].LastActivityAt, postToCheckLastUpdateAt.CreateAt)
|
||||
require.Equal(t, topInactiveChannels.Items[1].ID, channelPublic1.Id)
|
||||
})
|
||||
|
||||
t.Run("top inactive channels for user - u2 ", func(t *testing.T) {
|
||||
topInactiveChannels, err := ss.Channel().GetTopInactiveChannelsForUserSince(team.Id, u2.Id, 2, 0, 10)
|
||||
require.NoError(t, err)
|
||||
require.Len(t, topInactiveChannels.Items, 1)
|
||||
require.Equal(t, topInactiveChannels.Items[0].ID, channelPublic0.Id)
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
@@ -11,8 +11,6 @@ import (
|
||||
mock "github.com/stretchr/testify/mock"
|
||||
|
||||
store "github.com/mattermost/mattermost/server/v8/channels/store"
|
||||
|
||||
time "time"
|
||||
)
|
||||
|
||||
// ChannelStore is an autogenerated mock type for the ChannelStore type
|
||||
@@ -1774,110 +1772,6 @@ func (_m *ChannelStore) GetTeamMembersForChannel(channelID string) ([]string, er
|
||||
return r0, r1
|
||||
}
|
||||
|
||||
// GetTopChannelsForTeamSince provides a mock function with given fields: teamID, userID, since, offset, limit
|
||||
func (_m *ChannelStore) GetTopChannelsForTeamSince(teamID string, userID string, since int64, offset int, limit int) (*model.TopChannelList, error) {
|
||||
ret := _m.Called(teamID, userID, since, offset, limit)
|
||||
|
||||
var r0 *model.TopChannelList
|
||||
var r1 error
|
||||
if rf, ok := ret.Get(0).(func(string, string, int64, int, int) (*model.TopChannelList, error)); ok {
|
||||
return rf(teamID, userID, since, offset, limit)
|
||||
}
|
||||
if rf, ok := ret.Get(0).(func(string, string, int64, int, int) *model.TopChannelList); ok {
|
||||
r0 = rf(teamID, userID, since, offset, limit)
|
||||
} else {
|
||||
if ret.Get(0) != nil {
|
||||
r0 = ret.Get(0).(*model.TopChannelList)
|
||||
}
|
||||
}
|
||||
|
||||
if rf, ok := ret.Get(1).(func(string, string, int64, int, int) error); ok {
|
||||
r1 = rf(teamID, userID, since, offset, limit)
|
||||
} else {
|
||||
r1 = ret.Error(1)
|
||||
}
|
||||
|
||||
return r0, r1
|
||||
}
|
||||
|
||||
// GetTopChannelsForUserSince provides a mock function with given fields: userID, teamID, since, offset, limit
|
||||
func (_m *ChannelStore) GetTopChannelsForUserSince(userID string, teamID string, since int64, offset int, limit int) (*model.TopChannelList, error) {
|
||||
ret := _m.Called(userID, teamID, since, offset, limit)
|
||||
|
||||
var r0 *model.TopChannelList
|
||||
var r1 error
|
||||
if rf, ok := ret.Get(0).(func(string, string, int64, int, int) (*model.TopChannelList, error)); ok {
|
||||
return rf(userID, teamID, since, offset, limit)
|
||||
}
|
||||
if rf, ok := ret.Get(0).(func(string, string, int64, int, int) *model.TopChannelList); ok {
|
||||
r0 = rf(userID, teamID, since, offset, limit)
|
||||
} else {
|
||||
if ret.Get(0) != nil {
|
||||
r0 = ret.Get(0).(*model.TopChannelList)
|
||||
}
|
||||
}
|
||||
|
||||
if rf, ok := ret.Get(1).(func(string, string, int64, int, int) error); ok {
|
||||
r1 = rf(userID, teamID, since, offset, limit)
|
||||
} else {
|
||||
r1 = ret.Error(1)
|
||||
}
|
||||
|
||||
return r0, r1
|
||||
}
|
||||
|
||||
// GetTopInactiveChannelsForTeamSince provides a mock function with given fields: teamID, userID, since, offset, limit
|
||||
func (_m *ChannelStore) GetTopInactiveChannelsForTeamSince(teamID string, userID string, since int64, offset int, limit int) (*model.TopInactiveChannelList, error) {
|
||||
ret := _m.Called(teamID, userID, since, offset, limit)
|
||||
|
||||
var r0 *model.TopInactiveChannelList
|
||||
var r1 error
|
||||
if rf, ok := ret.Get(0).(func(string, string, int64, int, int) (*model.TopInactiveChannelList, error)); ok {
|
||||
return rf(teamID, userID, since, offset, limit)
|
||||
}
|
||||
if rf, ok := ret.Get(0).(func(string, string, int64, int, int) *model.TopInactiveChannelList); ok {
|
||||
r0 = rf(teamID, userID, since, offset, limit)
|
||||
} else {
|
||||
if ret.Get(0) != nil {
|
||||
r0 = ret.Get(0).(*model.TopInactiveChannelList)
|
||||
}
|
||||
}
|
||||
|
||||
if rf, ok := ret.Get(1).(func(string, string, int64, int, int) error); ok {
|
||||
r1 = rf(teamID, userID, since, offset, limit)
|
||||
} else {
|
||||
r1 = ret.Error(1)
|
||||
}
|
||||
|
||||
return r0, r1
|
||||
}
|
||||
|
||||
// GetTopInactiveChannelsForUserSince provides a mock function with given fields: teamID, userID, since, offset, limit
|
||||
func (_m *ChannelStore) GetTopInactiveChannelsForUserSince(teamID string, userID string, since int64, offset int, limit int) (*model.TopInactiveChannelList, error) {
|
||||
ret := _m.Called(teamID, userID, since, offset, limit)
|
||||
|
||||
var r0 *model.TopInactiveChannelList
|
||||
var r1 error
|
||||
if rf, ok := ret.Get(0).(func(string, string, int64, int, int) (*model.TopInactiveChannelList, error)); ok {
|
||||
return rf(teamID, userID, since, offset, limit)
|
||||
}
|
||||
if rf, ok := ret.Get(0).(func(string, string, int64, int, int) *model.TopInactiveChannelList); ok {
|
||||
r0 = rf(teamID, userID, since, offset, limit)
|
||||
} else {
|
||||
if ret.Get(0) != nil {
|
||||
r0 = ret.Get(0).(*model.TopInactiveChannelList)
|
||||
}
|
||||
}
|
||||
|
||||
if rf, ok := ret.Get(1).(func(string, string, int64, int, int) error); ok {
|
||||
r1 = rf(teamID, userID, since, offset, limit)
|
||||
} else {
|
||||
r1 = ret.Error(1)
|
||||
}
|
||||
|
||||
return r0, r1
|
||||
}
|
||||
|
||||
// GroupSyncedChannelCount provides a mock function with given fields:
|
||||
func (_m *ChannelStore) GroupSyncedChannelCount() (int64, error) {
|
||||
ret := _m.Called()
|
||||
@@ -2047,32 +1941,6 @@ func (_m *ChannelStore) PermanentDeleteMembersByUser(userID string) error {
|
||||
return r0
|
||||
}
|
||||
|
||||
// PostCountsByDuration provides a mock function with given fields: channelIDs, sinceUnixMillis, userID, duration, groupingLocation
|
||||
func (_m *ChannelStore) PostCountsByDuration(channelIDs []string, sinceUnixMillis int64, userID *string, duration model.PostCountGrouping, groupingLocation *time.Location) ([]*model.DurationPostCount, error) {
|
||||
ret := _m.Called(channelIDs, sinceUnixMillis, userID, duration, groupingLocation)
|
||||
|
||||
var r0 []*model.DurationPostCount
|
||||
var r1 error
|
||||
if rf, ok := ret.Get(0).(func([]string, int64, *string, model.PostCountGrouping, *time.Location) ([]*model.DurationPostCount, error)); ok {
|
||||
return rf(channelIDs, sinceUnixMillis, userID, duration, groupingLocation)
|
||||
}
|
||||
if rf, ok := ret.Get(0).(func([]string, int64, *string, model.PostCountGrouping, *time.Location) []*model.DurationPostCount); ok {
|
||||
r0 = rf(channelIDs, sinceUnixMillis, userID, duration, groupingLocation)
|
||||
} else {
|
||||
if ret.Get(0) != nil {
|
||||
r0 = ret.Get(0).([]*model.DurationPostCount)
|
||||
}
|
||||
}
|
||||
|
||||
if rf, ok := ret.Get(1).(func([]string, int64, *string, model.PostCountGrouping, *time.Location) error); ok {
|
||||
r1 = rf(channelIDs, sinceUnixMillis, userID, duration, groupingLocation)
|
||||
} else {
|
||||
r1 = ret.Error(1)
|
||||
}
|
||||
|
||||
return r0, r1
|
||||
}
|
||||
|
||||
// RemoveAllDeactivatedMembers provides a mock function with given fields: channelID
|
||||
func (_m *ChannelStore) RemoveAllDeactivatedMembers(channelID string) error {
|
||||
ret := _m.Called(channelID)
|
||||
|
||||
@@ -840,32 +840,6 @@ func (_m *PostStore) GetSingle(id string, inclDeleted bool) (*model.Post, error)
|
||||
return r0, r1
|
||||
}
|
||||
|
||||
// GetTopDMsForUserSince provides a mock function with given fields: userID, since, offset, limit
|
||||
func (_m *PostStore) GetTopDMsForUserSince(userID string, since int64, offset int, limit int) (*model.TopDMList, error) {
|
||||
ret := _m.Called(userID, since, offset, limit)
|
||||
|
||||
var r0 *model.TopDMList
|
||||
var r1 error
|
||||
if rf, ok := ret.Get(0).(func(string, int64, int, int) (*model.TopDMList, error)); ok {
|
||||
return rf(userID, since, offset, limit)
|
||||
}
|
||||
if rf, ok := ret.Get(0).(func(string, int64, int, int) *model.TopDMList); ok {
|
||||
r0 = rf(userID, since, offset, limit)
|
||||
} else {
|
||||
if ret.Get(0) != nil {
|
||||
r0 = ret.Get(0).(*model.TopDMList)
|
||||
}
|
||||
}
|
||||
|
||||
if rf, ok := ret.Get(1).(func(string, int64, int, int) error); ok {
|
||||
r1 = rf(userID, since, offset, limit)
|
||||
} else {
|
||||
r1 = ret.Error(1)
|
||||
}
|
||||
|
||||
return r0, r1
|
||||
}
|
||||
|
||||
// HasAutoResponsePostByUserSince provides a mock function with given fields: options, userId
|
||||
func (_m *PostStore) HasAutoResponsePostByUserSince(options model.GetPostsSinceOptions, userId string) (bool, error) {
|
||||
ret := _m.Called(options, userId)
|
||||
|
||||
@@ -156,58 +156,6 @@ func (_m *ReactionStore) GetForPostSince(postId string, since int64, excludeRemo
|
||||
return r0, r1
|
||||
}
|
||||
|
||||
// GetTopForTeamSince provides a mock function with given fields: teamID, userID, since, offset, limit
|
||||
func (_m *ReactionStore) GetTopForTeamSince(teamID string, userID string, since int64, offset int, limit int) (*model.TopReactionList, error) {
|
||||
ret := _m.Called(teamID, userID, since, offset, limit)
|
||||
|
||||
var r0 *model.TopReactionList
|
||||
var r1 error
|
||||
if rf, ok := ret.Get(0).(func(string, string, int64, int, int) (*model.TopReactionList, error)); ok {
|
||||
return rf(teamID, userID, since, offset, limit)
|
||||
}
|
||||
if rf, ok := ret.Get(0).(func(string, string, int64, int, int) *model.TopReactionList); ok {
|
||||
r0 = rf(teamID, userID, since, offset, limit)
|
||||
} else {
|
||||
if ret.Get(0) != nil {
|
||||
r0 = ret.Get(0).(*model.TopReactionList)
|
||||
}
|
||||
}
|
||||
|
||||
if rf, ok := ret.Get(1).(func(string, string, int64, int, int) error); ok {
|
||||
r1 = rf(teamID, userID, since, offset, limit)
|
||||
} else {
|
||||
r1 = ret.Error(1)
|
||||
}
|
||||
|
||||
return r0, r1
|
||||
}
|
||||
|
||||
// GetTopForUserSince provides a mock function with given fields: userID, teamID, since, offset, limit
|
||||
func (_m *ReactionStore) GetTopForUserSince(userID string, teamID string, since int64, offset int, limit int) (*model.TopReactionList, error) {
|
||||
ret := _m.Called(userID, teamID, since, offset, limit)
|
||||
|
||||
var r0 *model.TopReactionList
|
||||
var r1 error
|
||||
if rf, ok := ret.Get(0).(func(string, string, int64, int, int) (*model.TopReactionList, error)); ok {
|
||||
return rf(userID, teamID, since, offset, limit)
|
||||
}
|
||||
if rf, ok := ret.Get(0).(func(string, string, int64, int, int) *model.TopReactionList); ok {
|
||||
r0 = rf(userID, teamID, since, offset, limit)
|
||||
} else {
|
||||
if ret.Get(0) != nil {
|
||||
r0 = ret.Get(0).(*model.TopReactionList)
|
||||
}
|
||||
}
|
||||
|
||||
if rf, ok := ret.Get(1).(func(string, string, int64, int, int) error); ok {
|
||||
r1 = rf(userID, teamID, since, offset, limit)
|
||||
} else {
|
||||
r1 = ret.Error(1)
|
||||
}
|
||||
|
||||
return r0, r1
|
||||
}
|
||||
|
||||
// PermanentDeleteBatch provides a mock function with given fields: endTime, limit
|
||||
func (_m *ReactionStore) PermanentDeleteBatch(endTime int64, limit int64) (int64, error) {
|
||||
ret := _m.Called(endTime, limit)
|
||||
|
||||
@@ -549,39 +549,6 @@ func (_m *TeamStore) GetMembersByIds(teamID string, userIds []string, restrictio
|
||||
return r0, r1
|
||||
}
|
||||
|
||||
// GetNewTeamMembersSince provides a mock function with given fields: teamID, since, offset, limit, showFullName
|
||||
func (_m *TeamStore) GetNewTeamMembersSince(teamID string, since int64, offset int, limit int, showFullName bool) (*model.NewTeamMembersList, int64, error) {
|
||||
ret := _m.Called(teamID, since, offset, limit, showFullName)
|
||||
|
||||
var r0 *model.NewTeamMembersList
|
||||
var r1 int64
|
||||
var r2 error
|
||||
if rf, ok := ret.Get(0).(func(string, int64, int, int, bool) (*model.NewTeamMembersList, int64, error)); ok {
|
||||
return rf(teamID, since, offset, limit, showFullName)
|
||||
}
|
||||
if rf, ok := ret.Get(0).(func(string, int64, int, int, bool) *model.NewTeamMembersList); ok {
|
||||
r0 = rf(teamID, since, offset, limit, showFullName)
|
||||
} else {
|
||||
if ret.Get(0) != nil {
|
||||
r0 = ret.Get(0).(*model.NewTeamMembersList)
|
||||
}
|
||||
}
|
||||
|
||||
if rf, ok := ret.Get(1).(func(string, int64, int, int, bool) int64); ok {
|
||||
r1 = rf(teamID, since, offset, limit, showFullName)
|
||||
} else {
|
||||
r1 = ret.Get(1).(int64)
|
||||
}
|
||||
|
||||
if rf, ok := ret.Get(2).(func(string, int64, int, int, bool) error); ok {
|
||||
r2 = rf(teamID, since, offset, limit, showFullName)
|
||||
} else {
|
||||
r2 = ret.Error(2)
|
||||
}
|
||||
|
||||
return r0, r1, r2
|
||||
}
|
||||
|
||||
// GetTeamMembersForExport provides a mock function with given fields: userID
|
||||
func (_m *TeamStore) GetTeamMembersForExport(userID string) ([]*model.TeamMemberForExport, error) {
|
||||
ret := _m.Called(userID)
|
||||
|
||||
@@ -273,58 +273,6 @@ func (_m *ThreadStore) GetThreadsForUser(userId string, teamID string, opts mode
|
||||
return r0, r1
|
||||
}
|
||||
|
||||
// GetTopThreadsForTeamSince provides a mock function with given fields: teamID, userID, since, offset, limit
|
||||
func (_m *ThreadStore) GetTopThreadsForTeamSince(teamID string, userID string, since int64, offset int, limit int) (*model.TopThreadList, error) {
|
||||
ret := _m.Called(teamID, userID, since, offset, limit)
|
||||
|
||||
var r0 *model.TopThreadList
|
||||
var r1 error
|
||||
if rf, ok := ret.Get(0).(func(string, string, int64, int, int) (*model.TopThreadList, error)); ok {
|
||||
return rf(teamID, userID, since, offset, limit)
|
||||
}
|
||||
if rf, ok := ret.Get(0).(func(string, string, int64, int, int) *model.TopThreadList); ok {
|
||||
r0 = rf(teamID, userID, since, offset, limit)
|
||||
} else {
|
||||
if ret.Get(0) != nil {
|
||||
r0 = ret.Get(0).(*model.TopThreadList)
|
||||
}
|
||||
}
|
||||
|
||||
if rf, ok := ret.Get(1).(func(string, string, int64, int, int) error); ok {
|
||||
r1 = rf(teamID, userID, since, offset, limit)
|
||||
} else {
|
||||
r1 = ret.Error(1)
|
||||
}
|
||||
|
||||
return r0, r1
|
||||
}
|
||||
|
||||
// GetTopThreadsForUserSince provides a mock function with given fields: teamID, userID, since, offset, limit
|
||||
func (_m *ThreadStore) GetTopThreadsForUserSince(teamID string, userID string, since int64, offset int, limit int) (*model.TopThreadList, error) {
|
||||
ret := _m.Called(teamID, userID, since, offset, limit)
|
||||
|
||||
var r0 *model.TopThreadList
|
||||
var r1 error
|
||||
if rf, ok := ret.Get(0).(func(string, string, int64, int, int) (*model.TopThreadList, error)); ok {
|
||||
return rf(teamID, userID, since, offset, limit)
|
||||
}
|
||||
if rf, ok := ret.Get(0).(func(string, string, int64, int, int) *model.TopThreadList); ok {
|
||||
r0 = rf(teamID, userID, since, offset, limit)
|
||||
} else {
|
||||
if ret.Get(0) != nil {
|
||||
r0 = ret.Get(0).(*model.TopThreadList)
|
||||
}
|
||||
}
|
||||
|
||||
if rf, ok := ret.Get(1).(func(string, string, int64, int, int) error); ok {
|
||||
r1 = rf(teamID, userID, since, offset, limit)
|
||||
} else {
|
||||
r1 = ret.Error(1)
|
||||
}
|
||||
|
||||
return r0, r1
|
||||
}
|
||||
|
||||
// GetTotalThreads provides a mock function with given fields: userId, teamID, opts
|
||||
func (_m *ThreadStore) GetTotalThreads(userId string, teamID string, opts model.GetUserThreadsOpts) (int64, error) {
|
||||
ret := _m.Called(userId, teamID, opts)
|
||||
|
||||
@@ -62,7 +62,6 @@ func TestPostStore(t *testing.T, ss store.Store, s SqlStore) {
|
||||
t.Run("GetPostReminders", func(t *testing.T) { testGetPostReminders(t, ss, s) })
|
||||
t.Run("GetPostReminderMetadata", func(t *testing.T) { testGetPostReminderMetadata(t, ss, s) })
|
||||
t.Run("GetNthRecentPostTime", func(t *testing.T) { testGetNthRecentPostTime(t, ss) })
|
||||
t.Run("GetTopDMsForUserSince", func(t *testing.T) { testGetTopDMsForUserSince(t, ss, s) })
|
||||
t.Run("GetEditHistoryForPost", func(t *testing.T) { testGetEditHistoryForPost(t, ss) })
|
||||
}
|
||||
|
||||
@@ -4862,180 +4861,6 @@ func testGetNthRecentPostTime(t *testing.T, ss store.Store) {
|
||||
assert.IsType(t, &store.ErrNotFound{}, err)
|
||||
}
|
||||
|
||||
func testGetTopDMsForUserSince(t *testing.T, ss store.Store, s SqlStore) {
|
||||
// users
|
||||
user := model.User{Email: MakeEmail(), Username: model.NewId()}
|
||||
u1 := model.User{Email: MakeEmail(), Username: model.NewId()}
|
||||
u2 := model.User{Email: MakeEmail(), Username: model.NewId()}
|
||||
u3 := model.User{Email: MakeEmail(), Username: model.NewId()}
|
||||
u4 := model.User{Email: MakeEmail(), Username: model.NewId()}
|
||||
u5 := model.User{Email: MakeEmail(), Username: model.NewId()}
|
||||
|
||||
_, err := ss.User().Save(&user)
|
||||
require.NoError(t, err)
|
||||
_, err = ss.User().Save(&u1)
|
||||
require.NoError(t, err)
|
||||
_, err = ss.User().Save(&u2)
|
||||
require.NoError(t, err)
|
||||
_, err = ss.User().Save(&u3)
|
||||
require.NoError(t, err)
|
||||
_, err = ss.User().Save(&u4)
|
||||
require.NoError(t, err)
|
||||
_, err = ss.User().Save(&u5)
|
||||
require.NoError(t, err)
|
||||
bot := &model.Bot{
|
||||
Username: "bot_user",
|
||||
Description: "bot",
|
||||
OwnerId: model.NewId(),
|
||||
UserId: u5.Id,
|
||||
}
|
||||
|
||||
savedBot, nErr := ss.Bot().Save(bot)
|
||||
require.NoError(t, nErr)
|
||||
// user direct messages
|
||||
chUser1, nErr := ss.Channel().CreateDirectChannel(&u1, &user)
|
||||
require.NoError(t, nErr)
|
||||
chUser2, nErr := ss.Channel().CreateDirectChannel(&u2, &user)
|
||||
require.NoError(t, nErr)
|
||||
chUser3, nErr := ss.Channel().CreateDirectChannel(&u3, &user)
|
||||
require.NoError(t, nErr)
|
||||
// other user direct message
|
||||
chUser3User4, nErr := ss.Channel().CreateDirectChannel(&u3, &u4)
|
||||
require.NoError(t, nErr)
|
||||
|
||||
// bot direct message - should be ignored by top DMs
|
||||
botUser, err := ss.User().Get(context.Background(), savedBot.UserId)
|
||||
require.NoError(t, err)
|
||||
chBot, nErr := ss.Channel().CreateDirectChannel(&user, botUser)
|
||||
require.NoError(t, nErr)
|
||||
_, err = ss.Post().Save(&model.Post{
|
||||
ChannelId: chBot.Id,
|
||||
UserId: botUser.Id,
|
||||
})
|
||||
require.NoError(t, err)
|
||||
|
||||
// sample post data
|
||||
// for u1
|
||||
_, err = ss.Post().Save(&model.Post{
|
||||
ChannelId: chUser1.Id,
|
||||
UserId: u1.Id,
|
||||
})
|
||||
require.NoError(t, err)
|
||||
_, err = ss.Post().Save(&model.Post{
|
||||
ChannelId: chUser1.Id,
|
||||
UserId: user.Id,
|
||||
})
|
||||
require.NoError(t, err)
|
||||
// for u2: 1 post
|
||||
postToDelete, err := ss.Post().Save(&model.Post{
|
||||
ChannelId: chUser2.Id,
|
||||
UserId: u2.Id,
|
||||
})
|
||||
require.NoError(t, err)
|
||||
// create second post for u2: modify create at to a very old date to make sure it isn't counted
|
||||
_, err = ss.Post().Save(&model.Post{
|
||||
ChannelId: chUser2.Id,
|
||||
UserId: u2.Id,
|
||||
CreateAt: 100,
|
||||
})
|
||||
require.NoError(t, err)
|
||||
// for user-u3: 3 posts
|
||||
for i := 0; i < 3; i++ {
|
||||
_, err = ss.Post().Save(&model.Post{
|
||||
ChannelId: chUser3.Id,
|
||||
UserId: user.Id,
|
||||
})
|
||||
require.NoError(t, err)
|
||||
}
|
||||
// for u4-u3: 4 posts
|
||||
u3u4Post1, err := ss.Post().Save(&model.Post{
|
||||
ChannelId: chUser3User4.Id,
|
||||
UserId: u3.Id,
|
||||
})
|
||||
require.NoError(t, err)
|
||||
_, err = ss.Post().Save(&model.Post{
|
||||
ChannelId: chUser3User4.Id,
|
||||
UserId: u4.Id,
|
||||
})
|
||||
require.NoError(t, err)
|
||||
u3u4Post2, err := ss.Post().Save(&model.Post{
|
||||
ChannelId: chUser3User4.Id,
|
||||
UserId: u3.Id,
|
||||
})
|
||||
require.NoError(t, err)
|
||||
|
||||
_, err = ss.Post().Save(&model.Post{
|
||||
ChannelId: chUser3User4.Id,
|
||||
UserId: u4.Id,
|
||||
})
|
||||
require.NoError(t, err)
|
||||
t.Run("should return topDMs when userid is specified ", func(t *testing.T) {
|
||||
topDMs, storeErr := ss.Post().GetTopDMsForUserSince(user.Id, 100, 0, 100)
|
||||
require.NoError(t, storeErr)
|
||||
// len of topDMs.Items should be 3
|
||||
require.Len(t, topDMs.Items, 3)
|
||||
// check order, magnitude of items
|
||||
require.Equal(t, topDMs.Items[0].SecondParticipant.Id, u3.Id)
|
||||
require.Equal(t, topDMs.Items[0].MessageCount, int64(3))
|
||||
require.Equal(t, topDMs.Items[0].OutgoingMessageCount, int64(3))
|
||||
require.Equal(t, topDMs.Items[1].SecondParticipant.Id, u1.Id)
|
||||
require.Equal(t, topDMs.Items[1].MessageCount, int64(2))
|
||||
require.Equal(t, topDMs.Items[1].OutgoingMessageCount, int64(1))
|
||||
require.Equal(t, topDMs.Items[2].SecondParticipant.Id, u2.Id)
|
||||
require.Equal(t, topDMs.Items[2].MessageCount, int64(1))
|
||||
require.Equal(t, topDMs.Items[2].OutgoingMessageCount, int64(0))
|
||||
// this also ensures that u3-u4 conversation doesn't show up in others' top DMs.
|
||||
})
|
||||
t.Run("topDMs should only consider user's DM channels ", func(t *testing.T) {
|
||||
// u4 only takes part in one conversation
|
||||
topDMs, storeErr := ss.Post().GetTopDMsForUserSince(u4.Id, 100, 0, 100)
|
||||
require.NoError(t, storeErr)
|
||||
// len of topDMs.Items should be 3
|
||||
require.Len(t, topDMs.Items, 1)
|
||||
// check order, magnitude of items
|
||||
require.Equal(t, topDMs.Items[0].SecondParticipant.Id, u3.Id)
|
||||
require.Equal(t, topDMs.Items[0].MessageCount, int64(4))
|
||||
})
|
||||
t.Run("topDMs will not consider self dms", func(t *testing.T) {
|
||||
chUser, nErr := ss.Channel().CreateDirectChannel(&user, &user)
|
||||
require.NoError(t, nErr)
|
||||
_, err = ss.Post().Save(&model.Post{
|
||||
ChannelId: chUser.Id,
|
||||
UserId: user.Id,
|
||||
})
|
||||
// delete u2 post
|
||||
err := ss.Post().Delete(postToDelete.Id, 200, user.Id)
|
||||
require.NoError(t, err)
|
||||
// u4 only takes part in one conversation
|
||||
topDMs, err := ss.Post().GetTopDMsForUserSince(user.Id, 100, 0, 100)
|
||||
require.NoError(t, err)
|
||||
// len of topDMs.Items should be 3
|
||||
require.Len(t, topDMs.Items, 2)
|
||||
})
|
||||
t.Run("topDMs will not consider deleted second user", func(t *testing.T) {
|
||||
// u4 only takes part in one conversation
|
||||
topDMs, err := ss.Post().GetTopDMsForUserSince(u4.Id, 100, 0, 100)
|
||||
require.NoError(t, err)
|
||||
// len of topDMs.Items should be 1
|
||||
require.Len(t, topDMs.Items, 1)
|
||||
// delete user3
|
||||
err = ss.User().PermanentDelete(u3.Id)
|
||||
require.NoError(t, err)
|
||||
// delete user3 posts
|
||||
err = ss.Post().Delete(u3u4Post1.Id, 200, u3.Id)
|
||||
require.NoError(t, err)
|
||||
err = ss.Post().Delete(u3u4Post2.Id, 200, u3.Id)
|
||||
require.NoError(t, err)
|
||||
// delete channel memberships
|
||||
err = ss.Channel().PermanentDeleteMembersByUser(u3.Id)
|
||||
require.NoError(t, err)
|
||||
topDMs, err = ss.Post().GetTopDMsForUserSince(u4.Id, 100, 0, 100)
|
||||
require.NoError(t, err)
|
||||
// len of topDMs.Items should be 0 since u3 is deleted
|
||||
require.Len(t, topDMs.Items, 0)
|
||||
})
|
||||
}
|
||||
|
||||
func testGetEditHistoryForPost(t *testing.T, ss store.Store) {
|
||||
t.Run("should return edit history for post", func(t *testing.T) {
|
||||
// create a post
|
||||
|
||||
@@ -73,7 +73,6 @@ func TestTeamStore(t *testing.T, ss store.Store) {
|
||||
t.Run("GetTeamMembersForExport", func(t *testing.T) { testTeamStoreGetTeamMembersForExport(t, ss) })
|
||||
t.Run("GetTeamsForUserWithPagination", func(t *testing.T) { testTeamMembersWithPagination(t, ss) })
|
||||
t.Run("GroupSyncedTeamCount", func(t *testing.T) { testGroupSyncedTeamCount(t, ss) })
|
||||
t.Run("GetNewTeamMembersSince", func(t *testing.T) { testGetNewTeamMembersSince(t, ss) })
|
||||
}
|
||||
|
||||
func testTeamStoreSave(t *testing.T, ss store.Store) {
|
||||
@@ -3619,17 +3618,3 @@ func testGroupSyncedTeamCount(t *testing.T, ss store.Store) {
|
||||
require.NoError(t, err)
|
||||
require.GreaterOrEqual(t, countAfter, count+1)
|
||||
}
|
||||
|
||||
func testGetNewTeamMembersSince(t *testing.T, ss store.Store) {
|
||||
team, err := ss.Team().Save(&model.Team{
|
||||
DisplayName: NewTestId(),
|
||||
Name: NewTestId(),
|
||||
Email: MakeEmail(),
|
||||
Type: model.TeamInvite,
|
||||
GroupConstrained: model.NewBool(true),
|
||||
})
|
||||
require.NoError(t, err)
|
||||
|
||||
_, _, err = ss.Team().GetNewTeamMembersSince(team.Id, 0, 0, 1000, false)
|
||||
require.NoError(t, err)
|
||||
}
|
||||
|
||||
@@ -27,7 +27,6 @@ func TestThreadStore(t *testing.T, ss store.Store, s SqlStore) {
|
||||
t.Run("GetTeamsUnreadForUser", func(t *testing.T) { testGetTeamsUnreadForUser(t, ss) })
|
||||
t.Run("GetVarious", func(t *testing.T) { testVarious(t, ss) })
|
||||
t.Run("MarkAllAsReadByChannels", func(t *testing.T) { testMarkAllAsReadByChannels(t, ss) })
|
||||
t.Run("GetTopThreads", func(t *testing.T) { testGetTopThreads(t, ss) })
|
||||
t.Run("MarkAllAsReadByTeam", func(t *testing.T) { testMarkAllAsReadByTeam(t, ss) })
|
||||
t.Run("DeleteMembershipsForChannel", func(t *testing.T) { testDeleteMembershipsForChannel(t, ss) })
|
||||
}
|
||||
@@ -1349,347 +1348,6 @@ func testMarkAllAsReadByChannels(t *testing.T, ss store.Store) {
|
||||
})
|
||||
}
|
||||
|
||||
func testGetTopThreads(t *testing.T, ss store.Store) {
|
||||
// create two users
|
||||
u1 := model.User{
|
||||
Email: MakeEmail(),
|
||||
Username: model.NewId(),
|
||||
}
|
||||
|
||||
_, err := ss.User().Save(&u1)
|
||||
require.NoError(t, err)
|
||||
|
||||
u2 := model.User{
|
||||
Email: MakeEmail(),
|
||||
Username: model.NewId(),
|
||||
}
|
||||
|
||||
_, err = ss.User().Save(&u2)
|
||||
require.NoError(t, err)
|
||||
|
||||
u3 := model.User{
|
||||
Email: MakeEmail(),
|
||||
Username: model.NewId(),
|
||||
}
|
||||
|
||||
_, err = ss.User().Save(&u3)
|
||||
require.NoError(t, err)
|
||||
|
||||
t.Run("test get top team threads", func(t *testing.T) {
|
||||
const limit = 10
|
||||
team, err := ss.Team().Save(&model.Team{
|
||||
DisplayName: "DisplayName",
|
||||
Name: "team" + model.NewId(),
|
||||
Email: MakeEmail(),
|
||||
Type: model.TeamOpen,
|
||||
})
|
||||
require.NoError(t, err)
|
||||
channel, err := ss.Channel().Save(&model.Channel{
|
||||
TeamId: team.Id,
|
||||
DisplayName: "DisplayName",
|
||||
Name: "channel" + model.NewId(),
|
||||
Type: model.ChannelTypeOpen,
|
||||
}, -1)
|
||||
require.NoError(t, err)
|
||||
|
||||
post1, err := ss.Post().Save(&model.Post{
|
||||
ChannelId: channel.Id,
|
||||
UserId: u1.Id,
|
||||
})
|
||||
require.NoError(t, err)
|
||||
post2, err := ss.Post().Save(&model.Post{
|
||||
ChannelId: channel.Id,
|
||||
UserId: u2.Id,
|
||||
})
|
||||
require.NoError(t, err)
|
||||
threadStoreCreateReply(t, ss, channel.Id, post1.Id, post1.UserId, 2000)
|
||||
threadStoreCreateReply(t, ss, channel.Id, post1.Id, post1.UserId, 2000)
|
||||
|
||||
threadStoreCreateReply(t, ss, channel.Id, post2.Id, post1.UserId, 2000)
|
||||
|
||||
// get top threads
|
||||
topThreadsInTeam, err := ss.Thread().GetTopThreadsForTeamSince(team.Id, model.NewId(), 12, 0, limit)
|
||||
require.NoError(t, err)
|
||||
// require length of top threads to be 2
|
||||
require.Len(t, topThreadsInTeam.Items, 2)
|
||||
|
||||
// require first element to be post1 with 2 replyCount=2
|
||||
require.Equal(t, topThreadsInTeam.Items[0].PostId, post1.Id)
|
||||
require.Equal(t, topThreadsInTeam.Items[0].UserId, post1.UserId)
|
||||
require.Equal(t, topThreadsInTeam.Items[0].UserInformation.Id, post1.UserId)
|
||||
require.Equal(t, topThreadsInTeam.Items[0].Post.ReplyCount, int64(2))
|
||||
require.Equal(t, topThreadsInTeam.Items[0].Post.Message, post1.Message)
|
||||
// require second element to be post2 with 2 replyCount=2
|
||||
require.Equal(t, topThreadsInTeam.Items[1].PostId, post2.Id)
|
||||
require.Equal(t, topThreadsInTeam.Items[1].Post.ReplyCount, int64(1))
|
||||
require.Equal(t, topThreadsInTeam.Items[1].UserId, post2.UserId)
|
||||
require.Equal(t, topThreadsInTeam.Items[1].UserInformation.Id, post2.UserId)
|
||||
require.Equal(t, topThreadsInTeam.Items[1].Post.Message, post2.Message)
|
||||
|
||||
// require topThreads[i].Post is not null
|
||||
require.Equal(t, topThreadsInTeam.Items[0].Post.Id, post1.Id)
|
||||
require.Equal(t, topThreadsInTeam.Items[1].Post.Id, post2.Id)
|
||||
})
|
||||
t.Run("test get top user threads", func(t *testing.T) {
|
||||
const limit = 10
|
||||
team, err := ss.Team().Save(&model.Team{
|
||||
DisplayName: "DisplayName",
|
||||
Name: "team" + model.NewId(),
|
||||
Email: MakeEmail(),
|
||||
Type: model.TeamOpen,
|
||||
})
|
||||
require.NoError(t, err)
|
||||
channel, err := ss.Channel().Save(&model.Channel{
|
||||
TeamId: team.Id,
|
||||
DisplayName: "DisplayName",
|
||||
Name: "channel" + model.NewId(),
|
||||
Type: model.ChannelTypeOpen,
|
||||
}, -1)
|
||||
require.NoError(t, err)
|
||||
|
||||
post1, err := ss.Post().Save(&model.Post{
|
||||
ChannelId: channel.Id,
|
||||
UserId: u1.Id,
|
||||
})
|
||||
require.NoError(t, err)
|
||||
post2, err := ss.Post().Save(&model.Post{
|
||||
ChannelId: channel.Id,
|
||||
UserId: u2.Id,
|
||||
})
|
||||
require.NoError(t, err)
|
||||
post3, err := ss.Post().Save(&model.Post{
|
||||
ChannelId: channel.Id,
|
||||
UserId: u3.Id,
|
||||
})
|
||||
require.NoError(t, err)
|
||||
threadStoreCreateReply(t, ss, channel.Id, post1.Id, post1.UserId, 2000)
|
||||
threadStoreCreateReply(t, ss, channel.Id, post1.Id, post1.UserId, 2000)
|
||||
|
||||
threadStoreCreateReply(t, ss, channel.Id, post2.Id, post2.UserId, 2000)
|
||||
threadStoreCreateReply(t, ss, channel.Id, post2.Id, post2.UserId, 2000)
|
||||
threadStoreCreateReply(t, ss, channel.Id, post3.Id, post3.UserId, 2000)
|
||||
opts := store.ThreadMembershipOpts{
|
||||
Following: true,
|
||||
IncrementMentions: false,
|
||||
UpdateFollowing: true,
|
||||
UpdateViewedTimestamp: false,
|
||||
UpdateParticipants: false,
|
||||
}
|
||||
|
||||
// create threadmemberships entries.
|
||||
_, err = ss.Thread().MaintainMembership(post1.UserId, post1.Id, opts)
|
||||
require.NoError(t, err)
|
||||
_, err = ss.Thread().MaintainMembership(post2.UserId, post2.Id, opts)
|
||||
require.NoError(t, err)
|
||||
_, err = ss.Thread().MaintainMembership(post2.UserId, post3.Id, opts)
|
||||
require.NoError(t, err)
|
||||
|
||||
// get top threads by user
|
||||
topThreadsByUser1, err := ss.Thread().GetTopThreadsForUserSince(team.Id, post1.UserId, 12, 0, limit)
|
||||
require.NoError(t, err)
|
||||
topThreadsByUser2, err := ss.Thread().GetTopThreadsForUserSince(team.Id, post2.UserId, 12, 0, limit)
|
||||
require.NoError(t, err)
|
||||
// require length of top threads by users to be 1,2 respectively
|
||||
require.Len(t, topThreadsByUser1.Items, 1)
|
||||
require.Len(t, topThreadsByUser2.Items, 2)
|
||||
|
||||
// require first element of topThreadsByUser1 to be post1 with 2 replyCount=2
|
||||
require.Equal(t, topThreadsByUser1.Items[0].PostId, post1.Id)
|
||||
require.Equal(t, topThreadsByUser1.Items[0].Post.ReplyCount, int64(2))
|
||||
require.Equal(t, topThreadsByUser1.Items[0].Post.Message, post1.Message)
|
||||
require.Equal(t, topThreadsByUser1.Items[0].UserId, post1.UserId)
|
||||
require.Equal(t, topThreadsByUser1.Items[0].UserInformation.Id, post1.UserId)
|
||||
// require elements of topThreadsByUser2 to be post2 and post3 respectively
|
||||
require.Equal(t, topThreadsByUser2.Items[0].PostId, post2.Id)
|
||||
require.Equal(t, topThreadsByUser2.Items[0].Post.ReplyCount, int64(2))
|
||||
require.Equal(t, topThreadsByUser2.Items[0].Post.Message, post2.Message)
|
||||
require.Equal(t, topThreadsByUser2.Items[0].UserId, post2.UserId)
|
||||
require.Equal(t, topThreadsByUser2.Items[0].UserInformation.Id, post2.UserId)
|
||||
|
||||
require.Equal(t, topThreadsByUser2.Items[1].PostId, post3.Id)
|
||||
require.Equal(t, topThreadsByUser2.Items[1].Post.ReplyCount, int64(1))
|
||||
require.Equal(t, topThreadsByUser2.Items[1].Post.Message, post3.Message)
|
||||
require.Equal(t, topThreadsByUser2.Items[1].UserId, post3.UserId)
|
||||
require.Equal(t, topThreadsByUser2.Items[1].UserInformation.Id, post3.UserId)
|
||||
|
||||
// require topThreads[i].Post is not null
|
||||
require.Equal(t, topThreadsByUser1.Items[0].Post.Id, post1.Id)
|
||||
require.Equal(t, topThreadsByUser2.Items[1].Post.Id, post3.Id)
|
||||
})
|
||||
t.Run("test get top threads only from given teamid", func(t *testing.T) {
|
||||
const limit = 10
|
||||
team1, err := ss.Team().Save(&model.Team{
|
||||
DisplayName: "DisplayName",
|
||||
Name: "team" + model.NewId(),
|
||||
Email: MakeEmail(),
|
||||
Type: model.TeamOpen,
|
||||
})
|
||||
require.NoError(t, err)
|
||||
team2, err := ss.Team().Save(&model.Team{
|
||||
DisplayName: "DisplayName",
|
||||
Name: "team" + model.NewId(),
|
||||
Email: MakeEmail(),
|
||||
Type: model.TeamOpen,
|
||||
})
|
||||
require.NoError(t, err)
|
||||
channel1, err := ss.Channel().Save(&model.Channel{
|
||||
TeamId: team1.Id,
|
||||
DisplayName: "DisplayName",
|
||||
Name: "channel" + model.NewId(),
|
||||
Type: model.ChannelTypeOpen,
|
||||
}, -1)
|
||||
require.NoError(t, err)
|
||||
|
||||
channel2, err := ss.Channel().Save(&model.Channel{
|
||||
TeamId: team2.Id,
|
||||
DisplayName: "DisplayName",
|
||||
Name: "channel" + model.NewId(),
|
||||
Type: model.ChannelTypeOpen,
|
||||
}, -1)
|
||||
require.NoError(t, err)
|
||||
|
||||
post1, err := ss.Post().Save(&model.Post{
|
||||
ChannelId: channel1.Id,
|
||||
UserId: u1.Id,
|
||||
})
|
||||
require.NoError(t, err)
|
||||
post2, err := ss.Post().Save(&model.Post{
|
||||
ChannelId: channel2.Id,
|
||||
UserId: u2.Id,
|
||||
})
|
||||
require.NoError(t, err)
|
||||
threadStoreCreateReply(t, ss, channel1.Id, post1.Id, post1.UserId, 2000)
|
||||
threadStoreCreateReply(t, ss, channel1.Id, post1.Id, post1.UserId, 2000)
|
||||
|
||||
threadStoreCreateReply(t, ss, channel2.Id, post2.Id, post2.UserId, 2000)
|
||||
|
||||
// assert that getting top threads from teamid 1 doesn't have post1.Id
|
||||
|
||||
topThreadsTeam2, err := ss.Thread().GetTopThreadsForTeamSince(team2.Id, u1.Id, 12, 0, limit)
|
||||
require.NoError(t, err)
|
||||
require.Len(t, topThreadsTeam2.Items, 1)
|
||||
require.Equal(t, topThreadsTeam2.Items[0].Post.Id, post2.Id)
|
||||
})
|
||||
t.Run("test get top threads only from non-direct channels", func(t *testing.T) {
|
||||
const limit = 10
|
||||
team1, err := ss.Team().Save(&model.Team{
|
||||
DisplayName: "DisplayName",
|
||||
Name: "team" + model.NewId(),
|
||||
Email: MakeEmail(),
|
||||
Type: model.TeamOpen,
|
||||
})
|
||||
require.NoError(t, err)
|
||||
channel1, err := ss.Channel().CreateDirectChannel(&u1, &u2)
|
||||
require.NoError(t, err)
|
||||
|
||||
channel2, err := ss.Channel().Save(&model.Channel{
|
||||
TeamId: team1.Id,
|
||||
DisplayName: "DisplayName",
|
||||
Name: "channel" + model.NewId(),
|
||||
Type: model.ChannelTypeOpen,
|
||||
}, -1)
|
||||
require.NoError(t, err)
|
||||
|
||||
post1, err := ss.Post().Save(&model.Post{
|
||||
ChannelId: channel1.Id,
|
||||
UserId: u1.Id,
|
||||
})
|
||||
require.NoError(t, err)
|
||||
post2, err := ss.Post().Save(&model.Post{
|
||||
ChannelId: channel2.Id,
|
||||
UserId: u2.Id,
|
||||
})
|
||||
require.NoError(t, err)
|
||||
threadStoreCreateReply(t, ss, channel1.Id, post1.Id, post1.UserId, 2000)
|
||||
threadStoreCreateReply(t, ss, channel1.Id, post1.Id, post1.UserId, 2000)
|
||||
|
||||
threadStoreCreateReply(t, ss, channel2.Id, post2.Id, u1.Id, 2000)
|
||||
|
||||
opts := store.ThreadMembershipOpts{
|
||||
Following: true,
|
||||
IncrementMentions: false,
|
||||
UpdateFollowing: true,
|
||||
UpdateViewedTimestamp: false,
|
||||
UpdateParticipants: false,
|
||||
}
|
||||
|
||||
// create threadmemberships entries.
|
||||
_, err = ss.Thread().MaintainMembership(u1.Id, post1.Id, opts)
|
||||
require.NoError(t, err)
|
||||
_, err = ss.Thread().MaintainMembership(u1.Id, post2.Id, opts)
|
||||
require.NoError(t, err)
|
||||
_, err = ss.Thread().MaintainMembership(u2.Id, post1.Id, opts)
|
||||
require.NoError(t, err)
|
||||
_, err = ss.Thread().MaintainMembership(u2.Id, post2.Id, opts)
|
||||
require.NoError(t, err)
|
||||
|
||||
// assert that getting top threads from teamid 1 doesn't have DMs
|
||||
|
||||
topThreadsTeam1, err := ss.Thread().GetTopThreadsForTeamSince(team1.Id, u1.Id, 12, 0, limit)
|
||||
require.NoError(t, err)
|
||||
require.Len(t, topThreadsTeam1.Items, 1)
|
||||
require.Equal(t, topThreadsTeam1.Items[0].Post.Id, post2.Id)
|
||||
|
||||
// assert that getting top threads from user 1 doesn't contain dm threads.
|
||||
topUserThreads, err := ss.Thread().GetTopThreadsForUserSince(team1.Id, u1.Id, 12, 0, limit)
|
||||
require.NoError(t, err)
|
||||
require.Len(t, topUserThreads.Items, 1)
|
||||
require.Equal(t, topUserThreads.Items[0].Post.Id, post2.Id)
|
||||
})
|
||||
t.Run("test get top threads doesn't exceed duration", func(t *testing.T) {
|
||||
const limit = 10
|
||||
team, err := ss.Team().Save(&model.Team{
|
||||
DisplayName: "DisplayName",
|
||||
Name: "team" + model.NewId(),
|
||||
Email: MakeEmail(),
|
||||
Type: model.TeamOpen,
|
||||
})
|
||||
require.NoError(t, err)
|
||||
channel, err := ss.Channel().Save(&model.Channel{
|
||||
TeamId: team.Id,
|
||||
DisplayName: "DisplayName",
|
||||
Name: "channel" + model.NewId(),
|
||||
Type: model.ChannelTypeOpen,
|
||||
}, -1)
|
||||
require.NoError(t, err)
|
||||
|
||||
post1, err := ss.Post().Save(&model.Post{
|
||||
ChannelId: channel.Id,
|
||||
UserId: u1.Id,
|
||||
})
|
||||
require.NoError(t, err)
|
||||
// post 2 has replies after 10 ms unix time.
|
||||
post2, err := ss.Post().Save(&model.Post{
|
||||
ChannelId: channel.Id,
|
||||
UserId: u2.Id,
|
||||
CreateAt: 1,
|
||||
})
|
||||
require.NoError(t, err)
|
||||
threadStoreCreateReply(t, ss, channel.Id, post1.Id, post1.UserId, 2000)
|
||||
threadStoreCreateReply(t, ss, channel.Id, post1.Id, post1.UserId, 2000)
|
||||
|
||||
threadStoreCreateReply(t, ss, channel.Id, post2.Id, post1.UserId, 10)
|
||||
|
||||
// get top threads
|
||||
topThreadsInTeamNewer, err := ss.Thread().GetTopThreadsForTeamSince(team.Id, model.NewId(), 12, 0, limit)
|
||||
require.NoError(t, err)
|
||||
// require length of top threads to be 2
|
||||
require.Len(t, topThreadsInTeamNewer.Items, 1)
|
||||
|
||||
// require first element to be post1 with 2 replyCount=2
|
||||
require.Equal(t, topThreadsInTeamNewer.Items[0].PostId, post1.Id)
|
||||
|
||||
// get top threads
|
||||
topThreadsInTeamOlder, err := ss.Thread().GetTopThreadsForTeamSince(team.Id, model.NewId(), 9, 0, limit)
|
||||
require.NoError(t, err)
|
||||
// require length of top threads to be 2
|
||||
require.Len(t, topThreadsInTeamOlder.Items, 2)
|
||||
|
||||
// require first element to be post1 with 2 replyCount=2
|
||||
require.Equal(t, topThreadsInTeamOlder.Items[1].PostId, post2.Id)
|
||||
})
|
||||
}
|
||||
|
||||
func testMarkAllAsReadByTeam(t *testing.T, ss store.Store) {
|
||||
createThreadMembership := func(userID, postID string) {
|
||||
t.Helper()
|
||||
|
||||
@@ -1728,70 +1728,6 @@ func (s *TimerLayerChannelStore) GetTeamMembersForChannel(channelID string) ([]s
|
||||
return result, err
|
||||
}
|
||||
|
||||
func (s *TimerLayerChannelStore) GetTopChannelsForTeamSince(teamID string, userID string, since int64, offset int, limit int) (*model.TopChannelList, error) {
|
||||
start := time.Now()
|
||||
|
||||
result, err := s.ChannelStore.GetTopChannelsForTeamSince(teamID, userID, since, offset, limit)
|
||||
|
||||
elapsed := float64(time.Since(start)) / float64(time.Second)
|
||||
if s.Root.Metrics != nil {
|
||||
success := "false"
|
||||
if err == nil {
|
||||
success = "true"
|
||||
}
|
||||
s.Root.Metrics.ObserveStoreMethodDuration("ChannelStore.GetTopChannelsForTeamSince", success, elapsed)
|
||||
}
|
||||
return result, err
|
||||
}
|
||||
|
||||
func (s *TimerLayerChannelStore) GetTopChannelsForUserSince(userID string, teamID string, since int64, offset int, limit int) (*model.TopChannelList, error) {
|
||||
start := time.Now()
|
||||
|
||||
result, err := s.ChannelStore.GetTopChannelsForUserSince(userID, teamID, since, offset, limit)
|
||||
|
||||
elapsed := float64(time.Since(start)) / float64(time.Second)
|
||||
if s.Root.Metrics != nil {
|
||||
success := "false"
|
||||
if err == nil {
|
||||
success = "true"
|
||||
}
|
||||
s.Root.Metrics.ObserveStoreMethodDuration("ChannelStore.GetTopChannelsForUserSince", success, elapsed)
|
||||
}
|
||||
return result, err
|
||||
}
|
||||
|
||||
func (s *TimerLayerChannelStore) GetTopInactiveChannelsForTeamSince(teamID string, userID string, since int64, offset int, limit int) (*model.TopInactiveChannelList, error) {
|
||||
start := time.Now()
|
||||
|
||||
result, err := s.ChannelStore.GetTopInactiveChannelsForTeamSince(teamID, userID, since, offset, limit)
|
||||
|
||||
elapsed := float64(time.Since(start)) / float64(time.Second)
|
||||
if s.Root.Metrics != nil {
|
||||
success := "false"
|
||||
if err == nil {
|
||||
success = "true"
|
||||
}
|
||||
s.Root.Metrics.ObserveStoreMethodDuration("ChannelStore.GetTopInactiveChannelsForTeamSince", success, elapsed)
|
||||
}
|
||||
return result, err
|
||||
}
|
||||
|
||||
func (s *TimerLayerChannelStore) GetTopInactiveChannelsForUserSince(teamID string, userID string, since int64, offset int, limit int) (*model.TopInactiveChannelList, error) {
|
||||
start := time.Now()
|
||||
|
||||
result, err := s.ChannelStore.GetTopInactiveChannelsForUserSince(teamID, userID, since, offset, limit)
|
||||
|
||||
elapsed := float64(time.Since(start)) / float64(time.Second)
|
||||
if s.Root.Metrics != nil {
|
||||
success := "false"
|
||||
if err == nil {
|
||||
success = "true"
|
||||
}
|
||||
s.Root.Metrics.ObserveStoreMethodDuration("ChannelStore.GetTopInactiveChannelsForUserSince", success, elapsed)
|
||||
}
|
||||
return result, err
|
||||
}
|
||||
|
||||
func (s *TimerLayerChannelStore) GroupSyncedChannelCount() (int64, error) {
|
||||
start := time.Now()
|
||||
|
||||
@@ -2025,22 +1961,6 @@ func (s *TimerLayerChannelStore) PermanentDeleteMembersByUser(userID string) err
|
||||
return err
|
||||
}
|
||||
|
||||
func (s *TimerLayerChannelStore) PostCountsByDuration(channelIDs []string, sinceUnixMillis int64, userID *string, duration model.PostCountGrouping, groupingLocation *time.Location) ([]*model.DurationPostCount, error) {
|
||||
start := time.Now()
|
||||
|
||||
result, err := s.ChannelStore.PostCountsByDuration(channelIDs, sinceUnixMillis, userID, duration, groupingLocation)
|
||||
|
||||
elapsed := float64(time.Since(start)) / float64(time.Second)
|
||||
if s.Root.Metrics != nil {
|
||||
success := "false"
|
||||
if err == nil {
|
||||
success = "true"
|
||||
}
|
||||
s.Root.Metrics.ObserveStoreMethodDuration("ChannelStore.PostCountsByDuration", success, elapsed)
|
||||
}
|
||||
return result, err
|
||||
}
|
||||
|
||||
func (s *TimerLayerChannelStore) RemoveAllDeactivatedMembers(channelID string) error {
|
||||
start := time.Now()
|
||||
|
||||
@@ -5845,22 +5765,6 @@ func (s *TimerLayerPostStore) GetSingle(id string, inclDeleted bool) (*model.Pos
|
||||
return result, err
|
||||
}
|
||||
|
||||
func (s *TimerLayerPostStore) GetTopDMsForUserSince(userID string, since int64, offset int, limit int) (*model.TopDMList, error) {
|
||||
start := time.Now()
|
||||
|
||||
result, err := s.PostStore.GetTopDMsForUserSince(userID, since, offset, limit)
|
||||
|
||||
elapsed := float64(time.Since(start)) / float64(time.Second)
|
||||
if s.Root.Metrics != nil {
|
||||
success := "false"
|
||||
if err == nil {
|
||||
success = "true"
|
||||
}
|
||||
s.Root.Metrics.ObserveStoreMethodDuration("PostStore.GetTopDMsForUserSince", success, elapsed)
|
||||
}
|
||||
return result, err
|
||||
}
|
||||
|
||||
func (s *TimerLayerPostStore) HasAutoResponsePostByUserSince(options model.GetPostsSinceOptions, userId string) (bool, error) {
|
||||
start := time.Now()
|
||||
|
||||
@@ -6644,38 +6548,6 @@ func (s *TimerLayerReactionStore) GetForPostSince(postId string, since int64, ex
|
||||
return result, err
|
||||
}
|
||||
|
||||
func (s *TimerLayerReactionStore) GetTopForTeamSince(teamID string, userID string, since int64, offset int, limit int) (*model.TopReactionList, error) {
|
||||
start := time.Now()
|
||||
|
||||
result, err := s.ReactionStore.GetTopForTeamSince(teamID, userID, since, offset, limit)
|
||||
|
||||
elapsed := float64(time.Since(start)) / float64(time.Second)
|
||||
if s.Root.Metrics != nil {
|
||||
success := "false"
|
||||
if err == nil {
|
||||
success = "true"
|
||||
}
|
||||
s.Root.Metrics.ObserveStoreMethodDuration("ReactionStore.GetTopForTeamSince", success, elapsed)
|
||||
}
|
||||
return result, err
|
||||
}
|
||||
|
||||
func (s *TimerLayerReactionStore) GetTopForUserSince(userID string, teamID string, since int64, offset int, limit int) (*model.TopReactionList, error) {
|
||||
start := time.Now()
|
||||
|
||||
result, err := s.ReactionStore.GetTopForUserSince(userID, teamID, since, offset, limit)
|
||||
|
||||
elapsed := float64(time.Since(start)) / float64(time.Second)
|
||||
if s.Root.Metrics != nil {
|
||||
success := "false"
|
||||
if err == nil {
|
||||
success = "true"
|
||||
}
|
||||
s.Root.Metrics.ObserveStoreMethodDuration("ReactionStore.GetTopForUserSince", success, elapsed)
|
||||
}
|
||||
return result, err
|
||||
}
|
||||
|
||||
func (s *TimerLayerReactionStore) PermanentDeleteBatch(endTime int64, limit int64) (int64, error) {
|
||||
start := time.Now()
|
||||
|
||||
@@ -8675,22 +8547,6 @@ func (s *TimerLayerTeamStore) GetMembersByIds(teamID string, userIds []string, r
|
||||
return result, err
|
||||
}
|
||||
|
||||
func (s *TimerLayerTeamStore) GetNewTeamMembersSince(teamID string, since int64, offset int, limit int, showFullName bool) (*model.NewTeamMembersList, int64, error) {
|
||||
start := time.Now()
|
||||
|
||||
result, resultVar1, err := s.TeamStore.GetNewTeamMembersSince(teamID, since, offset, limit, showFullName)
|
||||
|
||||
elapsed := float64(time.Since(start)) / float64(time.Second)
|
||||
if s.Root.Metrics != nil {
|
||||
success := "false"
|
||||
if err == nil {
|
||||
success = "true"
|
||||
}
|
||||
s.Root.Metrics.ObserveStoreMethodDuration("TeamStore.GetNewTeamMembersSince", success, elapsed)
|
||||
}
|
||||
return result, resultVar1, err
|
||||
}
|
||||
|
||||
func (s *TimerLayerTeamStore) GetTeamMembersForExport(userID string) ([]*model.TeamMemberForExport, error) {
|
||||
start := time.Now()
|
||||
|
||||
@@ -9378,38 +9234,6 @@ func (s *TimerLayerThreadStore) GetThreadsForUser(userId string, teamID string,
|
||||
return result, err
|
||||
}
|
||||
|
||||
func (s *TimerLayerThreadStore) GetTopThreadsForTeamSince(teamID string, userID string, since int64, offset int, limit int) (*model.TopThreadList, error) {
|
||||
start := time.Now()
|
||||
|
||||
result, err := s.ThreadStore.GetTopThreadsForTeamSince(teamID, userID, since, offset, limit)
|
||||
|
||||
elapsed := float64(time.Since(start)) / float64(time.Second)
|
||||
if s.Root.Metrics != nil {
|
||||
success := "false"
|
||||
if err == nil {
|
||||
success = "true"
|
||||
}
|
||||
s.Root.Metrics.ObserveStoreMethodDuration("ThreadStore.GetTopThreadsForTeamSince", success, elapsed)
|
||||
}
|
||||
return result, err
|
||||
}
|
||||
|
||||
func (s *TimerLayerThreadStore) GetTopThreadsForUserSince(teamID string, userID string, since int64, offset int, limit int) (*model.TopThreadList, error) {
|
||||
start := time.Now()
|
||||
|
||||
result, err := s.ThreadStore.GetTopThreadsForUserSince(teamID, userID, since, offset, limit)
|
||||
|
||||
elapsed := float64(time.Since(start)) / float64(time.Second)
|
||||
if s.Root.Metrics != nil {
|
||||
success := "false"
|
||||
if err == nil {
|
||||
success = "true"
|
||||
}
|
||||
s.Root.Metrics.ObserveStoreMethodDuration("ThreadStore.GetTopThreadsForUserSince", success, elapsed)
|
||||
}
|
||||
return result, err
|
||||
}
|
||||
|
||||
func (s *TimerLayerThreadStore) GetTotalThreads(userId string, teamID string, opts model.GetUserThreadsOpts) (int64, error) {
|
||||
start := time.Now()
|
||||
|
||||
|
||||
Ссылка в новой задаче
Block a user