0
0
mirror of https://github.com/go-gitea/gitea.git synced 2025-07-24 10:44:32 -04:00

Fix the length

This commit is contained in:
Lunny Xiao 2025-04-17 12:58:46 -07:00
parent dd0caf7e16
commit a0080acc8f
No known key found for this signature in database
GPG Key ID: C3B7C91B632F738A

View File

@ -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)
}