diff options
author | Jesse Hallam <jesse.hallam@gmail.com> | 2018-03-26 17:55:35 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-03-26 17:55:35 -0400 |
commit | 8491ba5740e2d9942b2612ce06aef90bb10ad4c0 (patch) | |
tree | b58f596fef50e6a3bc79944e121476861047c250 /app/import.go | |
parent | 4a69c277a620308959ad6870d4e7c8240f9a166d (diff) | |
download | chat-8491ba5740e2d9942b2612ce06aef90bb10ad4c0.tar.gz chat-8491ba5740e2d9942b2612ce06aef90bb10ad4c0.tar.bz2 chat-8491ba5740e2d9942b2612ce06aef90bb10ad4c0.zip |
Relax 4k post message limit (#8478)
* MM-9661: rename POST_MESSAGE_MAX_RUNES to \0_v1
* MM-9661: s/4000/POST_MESSAGE_MAX_RUNES_V1/ in tests
* MM-9661: introduce POST_MESSAGE_MAX_RUNES_V2
* MM-9661: migrate Postgres Posts.Message column to TEXT from VARCHAR(4000)
This is safe to do in a production instance since the underyling type is
not changing. We explicitly don't do this automatically for MySQL, but
also don't need to since the ORM would have already created a TEXT column
for MySQL in that case.
* MM-9661: emit MaxPostSize in client config
This value remains unconfigurable at this time, but exposes the current
limit to the client. The limit remains at 4k in this commit.
* MM-9661: introduce and use SqlPostStore.GetMaxPostSize
Enforce a byte limitation in the database, and use 1/4 of that value as
the rune count limitation (assuming a worst case UTF-8 representation).
* move maxPostSizeCached, lastPostsCache and lastPostTimeCache out of the global context and onto the SqlPostStore
* address feedback from code review:
* ensure sqlstore unit tests are actually being run
* move global caches into SqlPostStore
* leverage sync.Once to address a race condition
* modify upgrade semantics to match new db semantics
gorp's behaviour on creating columns with a maximum length on Postgres
differs from MySQL:
* Postgres
* gorp uses TEXT for string columns without a maximum length
* gorp uses VARCHAR(N) for string columns with a maximum length of N
* MySQL
* gorp uses TEXT for string columns with a maximum length >= 256
* gorp uses VARCHAR(N) for string columns with a maximum length of N
* gorp defaults to a maximum length of 255, implying VARCHAR(255)
So the Message column has been TEXT on MySQL but VARCHAR(4000) on
Postgres. With the new, longer limits of 65535, and without changes to
gorp, the expected behaviour is TEXT on MySQL and VARCHAR(65535) on
Postgres. This commit makes the upgrade semantics match the new database
semantics.
Ideally, we'd revisit the gorp behaviour at a later time.
* allow TestMaxPostSize test cases to actually run in parallel
* default maxPostSizeCached to POST_MESSAGE_MAX_RUNES_V1 in case the once initializer panics
* fix casting error
* MM-9661: skip the schema migration for Postgres
It turns out resizing VARCHAR requires a rewrite in some versions of
Postgres, but migrating VARCHAR to TEXT does not. Given the increasing
complexity, let's defer the migration to the enduser instead.
Diffstat (limited to 'app/import.go')
-rw-r--r-- | app/import.go | 29 |
1 files changed, 15 insertions, 14 deletions
diff --git a/app/import.go b/app/import.go index e2e3aa1b7..23a315be7 100644 --- a/app/import.go +++ b/app/import.go @@ -1086,7 +1086,7 @@ func (a *App) ImportReaction(data *ReactionImportData, post *model.Post, dryRun } func (a *App) ImportReply(data *ReplyImportData, post *model.Post, dryRun bool) *model.AppError { - if err := validateReplyImportData(data, post.CreateAt); err != nil { + if err := validateReplyImportData(data, post.CreateAt, a.MaxPostSize()); err != nil { return err } @@ -1136,7 +1136,7 @@ func (a *App) ImportReply(data *ReplyImportData, post *model.Post, dryRun bool) } func (a *App) ImportPost(data *PostImportData, dryRun bool) *model.AppError { - if err := validatePostImportData(data); err != nil { + if err := validatePostImportData(data, a.MaxPostSize()); err != nil { return err } @@ -1271,14 +1271,14 @@ func validateReactionImportData(data *ReactionImportData, parentCreateAt int64) return nil } -func validateReplyImportData(data *ReplyImportData, parentCreateAt int64) *model.AppError { +func validateReplyImportData(data *ReplyImportData, parentCreateAt int64, maxPostSize int) *model.AppError { if data.User == nil { return model.NewAppError("BulkImport", "app.import.validate_reply_import_data.user_missing.error", nil, "", http.StatusBadRequest) } if data.Message == nil { return model.NewAppError("BulkImport", "app.import.validate_reply_import_data.message_missing.error", nil, "", http.StatusBadRequest) - } else if utf8.RuneCountInString(*data.Message) > model.POST_MESSAGE_MAX_RUNES { + } else if utf8.RuneCountInString(*data.Message) > maxPostSize { return model.NewAppError("BulkImport", "app.import.validate_reply_import_data.message_length.error", nil, "", http.StatusBadRequest) } @@ -1293,7 +1293,7 @@ func validateReplyImportData(data *ReplyImportData, parentCreateAt int64) *model return nil } -func validatePostImportData(data *PostImportData) *model.AppError { +func validatePostImportData(data *PostImportData, maxPostSize int) *model.AppError { if data.Team == nil { return model.NewAppError("BulkImport", "app.import.validate_post_import_data.team_missing.error", nil, "", http.StatusBadRequest) } @@ -1308,7 +1308,7 @@ func validatePostImportData(data *PostImportData) *model.AppError { if data.Message == nil { return model.NewAppError("BulkImport", "app.import.validate_post_import_data.message_missing.error", nil, "", http.StatusBadRequest) - } else if utf8.RuneCountInString(*data.Message) > model.POST_MESSAGE_MAX_RUNES { + } else if utf8.RuneCountInString(*data.Message) > maxPostSize { return model.NewAppError("BulkImport", "app.import.validate_post_import_data.message_length.error", nil, "", http.StatusBadRequest) } @@ -1326,7 +1326,7 @@ func validatePostImportData(data *PostImportData) *model.AppError { if data.Replies != nil { for _, reply := range *data.Replies { - validateReplyImportData(&reply, *data.CreateAt) + validateReplyImportData(&reply, *data.CreateAt, maxPostSize) } } @@ -1446,7 +1446,7 @@ func validateDirectChannelImportData(data *DirectChannelImportData) *model.AppEr } func (a *App) ImportDirectPost(data *DirectPostImportData, dryRun bool) *model.AppError { - if err := validateDirectPostImportData(data); err != nil { + if err := validateDirectPostImportData(data, a.MaxPostSize()); err != nil { return err } @@ -1572,7 +1572,7 @@ func (a *App) ImportDirectPost(data *DirectPostImportData, dryRun bool) *model.A return nil } -func validateDirectPostImportData(data *DirectPostImportData) *model.AppError { +func validateDirectPostImportData(data *DirectPostImportData, maxPostSize int) *model.AppError { if data.ChannelMembers == nil { return model.NewAppError("BulkImport", "app.import.validate_direct_post_import_data.channel_members_required.error", nil, "", http.StatusBadRequest) } @@ -1591,7 +1591,7 @@ func validateDirectPostImportData(data *DirectPostImportData) *model.AppError { if data.Message == nil { return model.NewAppError("BulkImport", "app.import.validate_direct_post_import_data.message_missing.error", nil, "", http.StatusBadRequest) - } else if utf8.RuneCountInString(*data.Message) > model.POST_MESSAGE_MAX_RUNES { + } else if utf8.RuneCountInString(*data.Message) > maxPostSize { return model.NewAppError("BulkImport", "app.import.validate_direct_post_import_data.message_length.error", nil, "", http.StatusBadRequest) } @@ -1624,7 +1624,7 @@ func validateDirectPostImportData(data *DirectPostImportData) *model.AppError { if data.Replies != nil { for _, reply := range *data.Replies { - validateReplyImportData(&reply, *data.CreateAt) + validateReplyImportData(&reply, *data.CreateAt, maxPostSize) } } @@ -1640,12 +1640,13 @@ func validateDirectPostImportData(data *DirectPostImportData) *model.AppError { func (a *App) OldImportPost(post *model.Post) { // Workaround for empty messages, which may be the case if they are webhook posts. firstIteration := true + maxPostSize := a.MaxPostSize() for messageRuneCount := utf8.RuneCountInString(post.Message); messageRuneCount > 0 || firstIteration; messageRuneCount = utf8.RuneCountInString(post.Message) { firstIteration = false var remainder string - if messageRuneCount > model.POST_MESSAGE_MAX_RUNES { - remainder = string(([]rune(post.Message))[model.POST_MESSAGE_MAX_RUNES:]) - post.Message = truncateRunes(post.Message, model.POST_MESSAGE_MAX_RUNES) + if messageRuneCount > maxPostSize { + remainder = string(([]rune(post.Message))[maxPostSize:]) + post.Message = truncateRunes(post.Message, maxPostSize) } else { remainder = "" } |