Skip to content

Commit a0080ac

Browse files
committed
Fix the length
1 parent dd0caf7 commit a0080ac

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

services/feed/feed.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import (
1515
"code.gitea.io/gitea/models/unit"
1616
user_model "code.gitea.io/gitea/models/user"
1717
"code.gitea.io/gitea/modules/cache"
18+
"code.gitea.io/gitea/modules/log"
1819
"code.gitea.io/gitea/modules/setting"
1920
"code.gitea.io/gitea/modules/util"
2021
)
@@ -34,6 +35,8 @@ func GetFeeds(ctx context.Context, opts activities_model.GetFeedsOptions) (activ
3435
return activities_model.GetFeeds(ctx, opts)
3536
}
3637

38+
const maxActionContentLength = 65535 // this is the max length of mysql text column, sqlite, postgres and mssql have a higher limit
39+
3740
// notifyWatchers creates batch of actions for every watcher.
3841
// It could insert duplicate actions for a repository action, like this:
3942
// * Original action: UserID=1 (the real actor), ActUserID=1
@@ -42,6 +45,10 @@ func GetFeeds(ctx context.Context, opts activities_model.GetFeedsOptions) (activ
4245
func notifyWatchers(ctx context.Context, act *activities_model.Action, watchers []*repo_model.Watch, permCode, permIssue, permPR []bool) error {
4346
// Add feed for actioner.
4447
act.UserID = act.ActUserID
48+
if len(act.Content) > maxActionContentLength {
49+
act.Content = util.EllipsisDisplayString(act.Content, maxActionContentLength)
50+
log.Warn("Action [%d, %s]'s content is too long, truncated to %d bytes", act.RepoID, act.OpType, maxActionContentLength)
51+
}
4552
if err := db.Insert(ctx, act); err != nil {
4653
return fmt.Errorf("insert new actioner: %w", err)
4754
}

0 commit comments

Comments
 (0)