diff options
author | Jesús Espino <jespinog@gmail.com> | 2018-08-24 09:53:44 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-08-24 09:53:44 +0200 |
commit | bba3bbd9f3e250cca0ce705e664382fe3ad6e78a (patch) | |
tree | 63b8e40450634949d6bc3f80346cd26b7639c49d /cmd/mattermost/commands | |
parent | 8bbee74ed811e7aa8167ad7cea6d05042a90f446 (diff) | |
download | chat-bba3bbd9f3e250cca0ce705e664382fe3ad6e78a.tar.gz chat-bba3bbd9f3e250cca0ce705e664382fe3ad6e78a.tar.bz2 chat-bba3bbd9f3e250cca0ce705e664382fe3ad6e78a.zip |
MM-11572: Force correct order on messages generated in the bulk (#9244)
Diffstat (limited to 'cmd/mattermost/commands')
-rw-r--r-- | cmd/mattermost/commands/sampledata.go | 29 |
1 files changed, 22 insertions, 7 deletions
diff --git a/cmd/mattermost/commands/sampledata.go b/cmd/mattermost/commands/sampledata.go index 0983ab0df..ed550bf6b 100644 --- a/cmd/mattermost/commands/sampledata.go +++ b/cmd/mattermost/commands/sampledata.go @@ -59,6 +59,15 @@ func randomPastTime(seconds int) int64 { return (today.Unix() * 1000) - int64(rand.Intn(seconds*1000)) } +func sortedRandomDates(size int) []int64 { + dates := make([]int64, size) + for i := 0; i < size; i++ { + dates[i] = randomPastTime(50000) + } + sort.Slice(dates, func(a, b int) bool { return dates[a] < dates[b] }) + return dates +} + func randomEmoji() string { emojis := []string{"+1", "-1", "heart", "blush"} return emojis[rand.Intn(len(emojis))] @@ -274,8 +283,10 @@ func sampleDataCmdF(command *cobra.Command, args []string) error { for team, channels := range teamsAndChannels { for _, channel := range channels { + dates := sortedRandomDates(postsPerChannel) + for i := 0; i < postsPerChannel; i++ { - postLine := createPost(team, channel, allUsers) + postLine := createPost(team, channel, allUsers, dates[i]) encoder.Encode(postLine) } } @@ -286,8 +297,10 @@ func sampleDataCmdF(command *cobra.Command, args []string) error { user2 := allUsers[rand.Intn(len(allUsers))] channelLine := createDirectChannel([]string{user1, user2}) encoder.Encode(channelLine) + + dates := sortedRandomDates(postsPerDirectChannel) for j := 0; j < postsPerDirectChannel; j++ { - postLine := createDirectPost([]string{user1, user2}) + postLine := createDirectPost([]string{user1, user2}, dates[j]) encoder.Encode(postLine) } } @@ -303,8 +316,10 @@ func sampleDataCmdF(command *cobra.Command, args []string) error { } channelLine := createDirectChannel(users) encoder.Encode(channelLine) + + dates := sortedRandomDates(postsPerGroupChannel) for j := 0; j < postsPerGroupChannel; j++ { - postLine := createDirectPost(users) + postLine := createDirectPost(users, dates[j]) encoder.Encode(postLine) } } @@ -529,9 +544,9 @@ func createChannel(idx int, teamName string) app.LineImportData { } } -func createPost(team string, channel string, allUsers []string) app.LineImportData { +func createPost(team string, channel string, allUsers []string, createAt int64) app.LineImportData { message := randomMessage(allUsers) - create_at := randomPastTime(50000) + create_at := createAt user := allUsers[rand.Intn(len(allUsers))] // Some messages are flagged by an user @@ -589,9 +604,9 @@ func createDirectChannel(members []string) app.LineImportData { } } -func createDirectPost(members []string) app.LineImportData { +func createDirectPost(members []string, createAt int64) app.LineImportData { message := randomMessage(members) - create_at := randomPastTime(50000) + create_at := createAt user := members[rand.Intn(len(members))] // Some messages are flagged by an user |