@@ -34,8 +34,11 @@ var pushQueue queue.Queue
34
34
// handle passed PR IDs and test the PRs
35
35
func handle (data ... queue.Data ) []queue.Data {
36
36
for _ , datum := range data {
37
+ // use new context every loop, to avoid keeping cache data forever
38
+ ctx := cache .WithCacheContext (db .DefaultContext )
39
+
37
40
opts := datum .([]* repo_module.PushUpdateOptions )
38
- if err := pushUpdates (opts ); err != nil {
41
+ if err := pushUpdates (ctx , opts ); err != nil {
39
42
log .Error ("pushUpdate failed: %v" , err )
40
43
}
41
44
}
@@ -73,7 +76,7 @@ func PushUpdates(opts []*repo_module.PushUpdateOptions) error {
73
76
}
74
77
75
78
// pushUpdates generates push action history feeds for push updating multiple refs
76
- func pushUpdates (optsList []* repo_module.PushUpdateOptions ) error {
79
+ func pushUpdates (ctx context. Context , optsList []* repo_module.PushUpdateOptions ) error {
77
80
if len (optsList ) == 0 {
78
81
return nil
79
82
}
@@ -122,15 +125,15 @@ func pushUpdates(optsList []*repo_module.PushUpdateOptions) error {
122
125
tagName := opts .TagName ()
123
126
if opts .IsDelRef () {
124
127
notification .NotifyPushCommits (
125
- db . DefaultContext , pusher , repo ,
128
+ ctx , pusher , repo ,
126
129
& repo_module.PushUpdateOptions {
127
130
RefFullName : git .TagPrefix + tagName ,
128
131
OldCommitID : opts .OldCommitID ,
129
132
NewCommitID : git .EmptySHA ,
130
133
}, repo_module .NewPushCommits ())
131
134
132
135
delTags = append (delTags , tagName )
133
- notification .NotifyDeleteRef (db . DefaultContext , pusher , repo , "tag" , opts .RefFullName )
136
+ notification .NotifyDeleteRef (ctx , pusher , repo , "tag" , opts .RefFullName )
134
137
} else { // is new tag
135
138
newCommit , err := gitRepo .GetCommit (opts .NewCommitID )
136
139
if err != nil {
@@ -142,15 +145,15 @@ func pushUpdates(optsList []*repo_module.PushUpdateOptions) error {
142
145
commits .CompareURL = repo .ComposeCompareURL (git .EmptySHA , opts .NewCommitID )
143
146
144
147
notification .NotifyPushCommits (
145
- db . DefaultContext , pusher , repo ,
148
+ ctx , pusher , repo ,
146
149
& repo_module.PushUpdateOptions {
147
150
RefFullName : git .TagPrefix + tagName ,
148
151
OldCommitID : git .EmptySHA ,
149
152
NewCommitID : opts .NewCommitID ,
150
153
}, commits )
151
154
152
155
addTags = append (addTags , tagName )
153
- notification .NotifyCreateRef (db . DefaultContext , pusher , repo , "tag" , opts .RefFullName , opts .NewCommitID )
156
+ notification .NotifyCreateRef (ctx , pusher , repo , "tag" , opts .RefFullName , opts .NewCommitID )
154
157
}
155
158
} else if opts .IsBranch () { // If is branch reference
156
159
if pusher == nil || pusher .ID != opts .PusherID {
@@ -190,7 +193,7 @@ func pushUpdates(optsList []*repo_module.PushUpdateOptions) error {
190
193
}
191
194
}
192
195
// Update the is empty and default_branch columns
193
- if err := repo_model .UpdateRepositoryCols (db . DefaultContext , repo , "default_branch" , "is_empty" ); err != nil {
196
+ if err := repo_model .UpdateRepositoryCols (ctx , repo , "default_branch" , "is_empty" ); err != nil {
194
197
return fmt .Errorf ("UpdateRepositoryCols: %w" , err )
195
198
}
196
199
}
@@ -199,7 +202,7 @@ func pushUpdates(optsList []*repo_module.PushUpdateOptions) error {
199
202
if err != nil {
200
203
return fmt .Errorf ("newCommit.CommitsBeforeLimit: %w" , err )
201
204
}
202
- notification .NotifyCreateRef (db . DefaultContext , pusher , repo , "branch" , opts .RefFullName , opts .NewCommitID )
205
+ notification .NotifyCreateRef (ctx , pusher , repo , "branch" , opts .RefFullName , opts .NewCommitID )
203
206
} else {
204
207
l , err = newCommit .CommitsBeforeUntil (opts .OldCommitID )
205
208
if err != nil {
@@ -259,7 +262,7 @@ func pushUpdates(optsList []*repo_module.PushUpdateOptions) error {
259
262
commits .Commits = commits .Commits [:setting .UI .FeedMaxCommitNum ]
260
263
}
261
264
262
- notification .NotifyPushCommits (db . DefaultContext , pusher , repo , opts , commits )
265
+ notification .NotifyPushCommits (ctx , pusher , repo , opts , commits )
263
266
264
267
if err = git_model .RemoveDeletedBranchByName (ctx , repo .ID , branch ); err != nil {
265
268
log .Error ("models.RemoveDeletedBranch %s/%s failed: %v" , repo .ID , branch , err )
@@ -270,22 +273,22 @@ func pushUpdates(optsList []*repo_module.PushUpdateOptions) error {
270
273
log .Error ("repo_module.CacheRef %s/%s failed: %v" , repo .ID , branch , err )
271
274
}
272
275
} else {
273
- notification .NotifyDeleteRef (db . DefaultContext , pusher , repo , "branch" , opts .RefFullName )
276
+ notification .NotifyDeleteRef (ctx , pusher , repo , "branch" , opts .RefFullName )
274
277
if err = pull_service .CloseBranchPulls (pusher , repo .ID , branch ); err != nil {
275
278
// close all related pulls
276
279
log .Error ("close related pull request failed: %v" , err )
277
280
}
278
281
}
279
282
280
283
// Even if user delete a branch on a repository which he didn't watch, he will be watch that.
281
- if err = repo_model .WatchIfAuto (db . DefaultContext , opts .PusherID , repo .ID , true ); err != nil {
284
+ if err = repo_model .WatchIfAuto (ctx , opts .PusherID , repo .ID , true ); err != nil {
282
285
log .Warn ("Fail to perform auto watch on user %v for repo %v: %v" , opts .PusherID , repo .ID , err )
283
286
}
284
287
} else {
285
288
log .Trace ("Non-tag and non-branch commits pushed." )
286
289
}
287
290
}
288
- if err := PushUpdateAddDeleteTags (repo , gitRepo , addTags , delTags ); err != nil {
291
+ if err := PushUpdateAddDeleteTags (ctx , repo , gitRepo , addTags , delTags ); err != nil {
289
292
return fmt .Errorf ("PushUpdateAddDeleteTags: %w" , err )
290
293
}
291
294
@@ -298,8 +301,8 @@ func pushUpdates(optsList []*repo_module.PushUpdateOptions) error {
298
301
}
299
302
300
303
// PushUpdateAddDeleteTags updates a number of added and delete tags
301
- func PushUpdateAddDeleteTags (repo * repo_model.Repository , gitRepo * git.Repository , addTags , delTags []string ) error {
302
- return db .WithTx (db . DefaultContext , func (ctx context.Context ) error {
304
+ func PushUpdateAddDeleteTags (ctx context. Context , repo * repo_model.Repository , gitRepo * git.Repository , addTags , delTags []string ) error {
305
+ return db .WithTx (ctx , func (ctx context.Context ) error {
303
306
if err := repo_model .PushUpdateDeleteTagsContext (ctx , repo , delTags ); err != nil {
304
307
return err
305
308
}
0 commit comments