Repository: go-gitea/gitea
File: services/feed/feed.go (Go)

Code before:
func userFeedCacheKey(userID int64) string {
	return fmt.Sprintf("user_feed_%d", userID)
}

func GetFeedsForDashboard(ctx context.Context, opts activities_model.GetFeedsOptions) (activities_model.ActionList, int, error) {
	opts.DontCount = opts.RequestedTeam == nil && opts.Date == ""
	results, cnt, err := activities_model.GetFeeds(ctx, opts)
	return results, util.Iif(opts.DontCount, -1, int(cnt)), err
}

// GetFeeds returns actions according to the provided options
func GetFeeds(ctx context.Context, opts activities_model.GetFeedsOptions) (activities_model.ActionList, int64, error) {
	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
// * Organization action: UserID=100 (the repo's org), ActUserID=1
// * Watcher action: UserID=20 (a user who is watching a repo), ActUserID=1
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)
	}

	// Add feed for organization
	if act.Repo.Owner.IsOrganization() && act.ActUserID != act.Repo.Owner.ID {
		act.ID = 0
		act.UserID = act.Repo.Owner.ID
		if err := db.Insert(ctx, act); err != nil {
			return fmt.Errorf("insert new actioner: %w", err)
		}
	}

	for i, watcher := range watchers {
		if act.ActUserID == watcher.UserID {
			continue
		}
		act.ID = 0
		act.UserID = watcher.UserID
		act.Repo.Units = nil

		switch act.OpType {

Review comment (suggestion):
I do not think the `if` check is useful to end users or site admin.

If you think it is still useful to show the "warn", you could just use `EllipsisDisplayStringX` to check whether the text is truncated by checking `right!=""`

Code after:
	results, cnt, err := activities_model.GetFeeds(ctx, opts)
	return results, util.Iif(opts.DontCount, -1, int(cnt)), err
}

// GetFeeds returns actions according to the provided options
func GetFeeds(ctx context.Context, opts activities_model.GetFeedsOptions) (activities_model.ActionList, int64, error) {
	return activities_model.GetFeeds(ctx, opts)
}

// 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
// * Organization action: UserID=100 (the repo's org), ActUserID=1
// * Watcher action: UserID=20 (a user who is watching a repo), ActUserID=1
func notifyWatchers(ctx context.Context, act *activities_model.Action, watchers []*repo_model.Watch, permCode, permIssue, permPR []bool) error {
	// MySQL has TEXT length limit 65535.
	// Sometimes the content is "field1|field2|field3", sometimes the content is JSON (ActionMirrorSyncPush, ActionCommitRepo, ActionPushTag, etc...)
	if left, right := util.EllipsisDisplayStringX(act.Content, 65535); right != "" {
		if strings.HasPrefix(act.Content, `{"`) && strings.HasSuffix(act.Content, `}`) {
			// FIXME: at the moment we can do nothing if the content is JSON and it is too long
			act.Content = "{}"
		} else {
			act.Content = left
		}
	}

	// Add feed for actor.
	act.UserID = act.ActUserID
	if err := db.Insert(ctx, act); err != nil {
		return fmt.Errorf("insert new actioner: %w", err)
	}

	// Add feed for organization
	if act.Repo.Owner.IsOrganization() && act.ActUserID != act.Repo.Owner.ID {
		act.ID = 0
		act.UserID = act.Repo.Owner.ID
		if err := db.Insert(ctx, act); err != nil {
			return fmt.Errorf("insert new actioner: %w", err)
		}
	}

	for i, watcher := range watchers {
		if act.ActUserID == watcher.UserID {
			continue
		}
		act.ID = 0
		act.UserID = watcher.UserID
		act.Repo.Units = nil

		switch act.OpType {
		case activities_model.ActionCommitRepo, activities_model.ActionPushTag, activities_model.ActionDeleteTag, activities_model.ActionPublishRelease, activities_model.ActionDeleteBranch: