@@ -6,23 +6,18 @@ package feed
6
6
import (
7
7
"context"
8
8
"fmt"
9
- "strconv "
9
+ "strings "
10
10
11
11
activities_model "code.gitea.io/gitea/models/activities"
12
12
"code.gitea.io/gitea/models/db"
13
13
access_model "code.gitea.io/gitea/models/perm/access"
14
14
repo_model "code.gitea.io/gitea/models/repo"
15
15
"code.gitea.io/gitea/models/unit"
16
16
user_model "code.gitea.io/gitea/models/user"
17
- "code.gitea.io/gitea/modules/cache"
18
17
"code.gitea.io/gitea/modules/setting"
19
18
"code.gitea.io/gitea/modules/util"
20
19
)
21
20
22
- func userFeedCacheKey (userID int64 ) string {
23
- return fmt .Sprintf ("user_feed_%d" , userID )
24
- }
25
-
26
21
func GetFeedsForDashboard (ctx context.Context , opts activities_model.GetFeedsOptions ) (activities_model.ActionList , int , error ) {
27
22
opts .DontCount = opts .RequestedTeam == nil && opts .Date == ""
28
23
results , cnt , err := activities_model .GetFeeds (ctx , opts )
@@ -40,7 +35,18 @@ func GetFeeds(ctx context.Context, opts activities_model.GetFeedsOptions) (activ
40
35
// * Organization action: UserID=100 (the repo's org), ActUserID=1
41
36
// * Watcher action: UserID=20 (a user who is watching a repo), ActUserID=1
42
37
func notifyWatchers (ctx context.Context , act * activities_model.Action , watchers []* repo_model.Watch , permCode , permIssue , permPR []bool ) error {
43
- // Add feed for actioner.
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
+ }
47
+ }
48
+
49
+ // Add feed for actor.
44
50
act .UserID = act .ActUserID
45
51
if err := db .Insert (ctx , act ); err != nil {
46
52
return fmt .Errorf ("insert new actioner: %w" , err )
@@ -76,24 +82,18 @@ func notifyWatchers(ctx context.Context, act *activities_model.Action, watchers
76
82
if ! permPR [i ] {
77
83
continue
78
84
}
85
+ default :
79
86
}
80
87
81
88
if err := db .Insert (ctx , act ); err != nil {
82
89
return fmt .Errorf ("insert new action: %w" , err )
83
90
}
84
-
85
- total , err := activities_model .CountUserFeeds (ctx , act .UserID )
86
- if err != nil {
87
- return fmt .Errorf ("count user feeds: %w" , err )
88
- }
89
-
90
- _ = cache .GetCache ().Put (userFeedCacheKey (act .UserID ), strconv .FormatInt (total , 10 ), setting .CacheService .TTLSeconds ())
91
91
}
92
92
93
93
return nil
94
94
}
95
95
96
- // NotifyWatchersActions creates batch of actions for every watcher.
96
+ // NotifyWatchers creates batch of actions for every watcher.
97
97
func NotifyWatchers (ctx context.Context , acts ... * activities_model.Action ) error {
98
98
return db .WithTx (ctx , func (ctx context.Context ) error {
99
99
if len (acts ) == 0 {
0 commit comments