@@ -6,23 +6,18 @@ package feed
66import  (
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" 
1817	"code.gitea.io/gitea/modules/setting" 
1918	"code.gitea.io/gitea/modules/util" 
2019)
2120
22- func  userFeedCacheKey (userID  int64 ) string  {
23- 	return  fmt .Sprintf ("user_feed_%d" , userID )
24- }
25- 
2621func  GetFeedsForDashboard (ctx  context.Context , opts  activities_model.GetFeedsOptions ) (activities_model.ActionList , int , error ) {
2722	opts .DontCount  =  opts .RequestedTeam  ==  nil  &&  opts .Date  ==  "" 
2823	results , cnt , err  :=  activities_model .GetFeeds (ctx , opts )
@@ -40,7 +35,18 @@ func GetFeeds(ctx context.Context, opts activities_model.GetFeedsOptions) (activ
4035// * Organization action: UserID=100 (the repo's org), ActUserID=1 
4136// * Watcher action: UserID=20 (a user who is watching a repo), ActUserID=1 
4237func  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. 
4450	act .UserID  =  act .ActUserID 
4551	if  err  :=  db .Insert (ctx , act ); err  !=  nil  {
4652		return  fmt .Errorf ("insert new actioner: %w" , err )
@@ -76,24 +82,18 @@ func notifyWatchers(ctx context.Context, act *activities_model.Action, watchers
7682			if  ! permPR [i ] {
7783				continue 
7884			}
85+ 		default :
7986		}
8087
8188		if  err  :=  db .Insert (ctx , act ); err  !=  nil  {
8289			return  fmt .Errorf ("insert new action: %w" , err )
8390		}
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 ())
9191	}
9292
9393	return  nil 
9494}
9595
96- // NotifyWatchersActions  creates batch of actions for every watcher. 
96+ // NotifyWatchers  creates batch of actions for every watcher. 
9797func  NotifyWatchers (ctx  context.Context , acts  ... * activities_model.Action ) error  {
9898	return  db .WithTx (ctx , func (ctx  context.Context ) error  {
9999		if  len (acts ) ==  0  {
0 commit comments