From a0080acc8f6afe7c541f1b3c8db88b43bf8a6d7d Mon Sep 17 00:00:00 2001 From: Lunny Xiao Date: Thu, 17 Apr 2025 12:58:46 -0700 Subject: [PATCH] Fix the length --- services/feed/feed.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/services/feed/feed.go b/services/feed/feed.go index 38a4e25308..cf607f32c0 100644 --- a/services/feed/feed.go +++ b/services/feed/feed.go @@ -15,6 +15,7 @@ import ( "code.gitea.io/gitea/models/unit" user_model "code.gitea.io/gitea/models/user" "code.gitea.io/gitea/modules/cache" + "code.gitea.io/gitea/modules/log" "code.gitea.io/gitea/modules/setting" "code.gitea.io/gitea/modules/util" ) @@ -34,6 +35,8 @@ func GetFeeds(ctx context.Context, opts activities_model.GetFeedsOptions) (activ return activities_model.GetFeeds(ctx, opts) } +const maxActionContentLength = 65535 // this is the max length of mysql text column, sqlite, postgres and mssql have a higher limit + // notifyWatchers creates batch of actions for every watcher. // It could insert duplicate actions for a repository action, like this: // * Original action: UserID=1 (the real actor), ActUserID=1 @@ -42,6 +45,10 @@ func GetFeeds(ctx context.Context, opts activities_model.GetFeedsOptions) (activ func notifyWatchers(ctx context.Context, act *activities_model.Action, watchers []*repo_model.Watch, permCode, permIssue, permPR []bool) error { // Add feed for actioner. act.UserID = act.ActUserID + if len(act.Content) > maxActionContentLength { + act.Content = util.EllipsisDisplayString(act.Content, maxActionContentLength) + log.Warn("Action [%d, %s]'s content is too long, truncated to %d bytes", act.RepoID, act.OpType, maxActionContentLength) + } if err := db.Insert(ctx, act); err != nil { return fmt.Errorf("insert new actioner: %w", err) }