Skip to content

Commit c5f735a

Browse files
committed
fix
1 parent a0080ac commit c5f735a

File tree

1 file changed

+15
-22
lines changed

1 file changed

+15
-22
lines changed

services/feed/feed.go

Lines changed: 15 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -6,24 +6,18 @@ package feed
66
import (
77
"context"
88
"fmt"
9-
"strconv"
9+
"strings"
1010

1111
activities_model "code.gitea.io/gitea/models/activities"
1212
"code.gitea.io/gitea/models/db"
1313
access_model "code.gitea.io/gitea/models/perm/access"
1414
repo_model "code.gitea.io/gitea/models/repo"
1515
"code.gitea.io/gitea/models/unit"
1616
user_model "code.gitea.io/gitea/models/user"
17-
"code.gitea.io/gitea/modules/cache"
18-
"code.gitea.io/gitea/modules/log"
1917
"code.gitea.io/gitea/modules/setting"
2018
"code.gitea.io/gitea/modules/util"
2119
)
2220

23-
func userFeedCacheKey(userID int64) string {
24-
return fmt.Sprintf("user_feed_%d", userID)
25-
}
26-
2721
func GetFeedsForDashboard(ctx context.Context, opts activities_model.GetFeedsOptions) (activities_model.ActionList, int, error) {
2822
opts.DontCount = opts.RequestedTeam == nil && opts.Date == ""
2923
results, cnt, err := activities_model.GetFeeds(ctx, opts)
@@ -35,20 +29,25 @@ func GetFeeds(ctx context.Context, opts activities_model.GetFeedsOptions) (activ
3529
return activities_model.GetFeeds(ctx, opts)
3630
}
3731

38-
const maxActionContentLength = 65535 // this is the max length of mysql text column, sqlite, postgres and mssql have a higher limit
39-
4032
// notifyWatchers creates batch of actions for every watcher.
4133
// It could insert duplicate actions for a repository action, like this:
4234
// * Original action: UserID=1 (the real actor), ActUserID=1
4335
// * Organization action: UserID=100 (the repo's org), ActUserID=1
4436
// * Watcher action: UserID=20 (a user who is watching a repo), ActUserID=1
4537
func notifyWatchers(ctx context.Context, act *activities_model.Action, watchers []*repo_model.Watch, permCode, permIssue, permPR []bool) error {
46-
// Add feed for actioner.
47-
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)
38+
// MySQL has TEXT length limit 65535.
39+
// Sometimes the content is "field1|field2|field3", sometimes the content is JSON (ActionMirrorSyncPush, ActionCommitRepo, ActionPushTag, etc...)
40+
if left, right := util.EllipsisDisplayStringX(act.Content, 65535); right != "" {
41+
if strings.HasPrefix(act.Content, `{"`) && strings.HasSuffix(act.Content, `}`) {
42+
// FIXME: at the moment we can do nothing if the content is JSON and it is too long
43+
act.Content = "{}"
44+
} else {
45+
act.Content = left
46+
}
5147
}
48+
49+
// Add feed for actor.
50+
act.UserID = act.ActUserID
5251
if err := db.Insert(ctx, act); err != nil {
5352
return fmt.Errorf("insert new actioner: %w", err)
5453
}
@@ -83,24 +82,18 @@ func notifyWatchers(ctx context.Context, act *activities_model.Action, watchers
8382
if !permPR[i] {
8483
continue
8584
}
85+
default:
8686
}
8787

8888
if err := db.Insert(ctx, act); err != nil {
8989
return fmt.Errorf("insert new action: %w", err)
9090
}
91-
92-
total, err := activities_model.CountUserFeeds(ctx, act.UserID)
93-
if err != nil {
94-
return fmt.Errorf("count user feeds: %w", err)
95-
}
96-
97-
_ = cache.GetCache().Put(userFeedCacheKey(act.UserID), strconv.FormatInt(total, 10), setting.CacheService.TTLSeconds())
9891
}
9992

10093
return nil
10194
}
10295

103-
// NotifyWatchersActions creates batch of actions for every watcher.
96+
// NotifyWatchers creates batch of actions for every watcher.
10497
func NotifyWatchers(ctx context.Context, acts ...*activities_model.Action) error {
10598
return db.WithTx(ctx, func(ctx context.Context) error {
10699
if len(acts) == 0 {

0 commit comments

Comments
 (0)