@@ -18,7 +18,6 @@ import (
1818 "code.gitea.io/gitea/modules/git"
1919 "code.gitea.io/gitea/modules/log"
2020 notify_service "code.gitea.io/gitea/services/notify"
21- "code.gitea.io/gitea/services/storagecleanup"
2221)
2322
2423// NewIssue creates new issue with labels for repository.
@@ -189,13 +188,10 @@ func DeleteIssue(ctx context.Context, doer *user_model.User, gitRepo *git.Reposi
189188 }
190189
191190 // delete entries in database
192- toBeCleanedDeletions , err := deleteIssue (ctx , issue , true )
193- if err != nil {
191+ if err := deleteIssue (ctx , issue , true ); err != nil {
194192 return err
195193 }
196194
197- storagecleanup .AddDeletionsToCleanQueue (ctx , toBeCleanedDeletions )
198-
199195 // delete pull request related git data
200196 if issue .IsPull && gitRepo != nil {
201197 if err := gitRepo .RemoveReference (issue .PullRequest .GetGitHeadRefName ()); err != nil {
@@ -258,37 +254,36 @@ func GetRefEndNamesAndURLs(issues []*issues_model.Issue, repoLink string) (map[i
258254}
259255
260256// deleteIssue deletes the issue
261- func deleteIssue (ctx context.Context , issue * issues_model.Issue , deleteAttachments bool ) ([]int64 , error ) {
262- return db .WithTx2 (ctx , func (ctx context.Context ) ([]int64 , error ) {
263- toBeCleanedDeletions := make ([]int64 , 0 )
257+ func deleteIssue (ctx context.Context , issue * issues_model.Issue , deleteAttachments bool ) error {
258+ return db .WithTx (ctx , func (ctx context.Context ) error {
264259 if _ , err := db .GetEngine (ctx ).ID (issue .ID ).NoAutoCondition ().Delete (issue ); err != nil {
265- return nil , err
260+ return err
266261 }
267262
268263 // update the total issue numbers
269264 if err := repo_model .UpdateRepoIssueNumbers (ctx , issue .RepoID , issue .IsPull , false ); err != nil {
270- return nil , err
265+ return err
271266 }
272267 // if the issue is closed, update the closed issue numbers
273268 if issue .IsClosed {
274269 if err := repo_model .UpdateRepoIssueNumbers (ctx , issue .RepoID , issue .IsPull , true ); err != nil {
275- return nil , err
270+ return err
276271 }
277272 }
278273
279274 if err := issues_model .UpdateMilestoneCounters (ctx , issue .MilestoneID ); err != nil {
280- return nil , fmt .Errorf ("error updating counters for milestone id %d: %w" ,
275+ return fmt .Errorf ("error updating counters for milestone id %d: %w" ,
281276 issue .MilestoneID , err )
282277 }
283278
284279 if err := activities_model .DeleteIssueActions (ctx , issue .RepoID , issue .ID , issue .Index ); err != nil {
285- return nil , err
280+ return err
286281 }
287282
288283 if deleteAttachments {
289284 // find attachments related to this issue and remove them
290285 if err := issue .LoadAttachments (ctx ); err != nil {
291- return nil , err
286+ return err
292287 }
293288 }
294289
@@ -311,82 +306,66 @@ func deleteIssue(ctx context.Context, issue *issues_model.Issue, deleteAttachmen
311306 & issues_model.Comment {DependentIssueID : issue .ID },
312307 & issues_model.IssuePin {IssueID : issue .ID },
313308 ); err != nil {
314- return nil , err
309+ return err
315310 }
316311
317312 for _ , comment := range issue .Comments {
318- deletions , err := deleteComment (ctx , comment , deleteAttachments )
319- if err != nil {
320- return nil , fmt .Errorf ("deleteComment [comment_id: %d]: %w" , comment .ID , err )
321- }
322- if deleteAttachments {
323- toBeCleanedDeletions = append (toBeCleanedDeletions , deletions ... )
313+ if err := deleteComment (ctx , comment , deleteAttachments ); err != nil {
314+ return fmt .Errorf ("deleteComment [comment_id: %d]: %w" , comment .ID , err )
324315 }
325316 }
326317
327318 if deleteAttachments {
328319 // delete issue attachments
329320 if err := issue .LoadAttachments (ctx ); err != nil {
330- return nil , err
321+ return err
331322 }
332- deletions , err := repo_model .DeleteAttachments (ctx , issue .Attachments )
333- if err != nil {
334- return nil , err
323+ if err := repo_model .DeleteAttachments (ctx , issue .Attachments ); err != nil {
324+ return err
335325 }
336- toBeCleanedDeletions = append (toBeCleanedDeletions , deletions ... )
337326 }
338- return toBeCleanedDeletions , nil
327+ return nil
339328 })
340329}
341330
342331// DeleteOrphanedIssues delete issues without a repo
343332func DeleteOrphanedIssues (ctx context.Context ) error {
344- toBeCleanedDeletions := make ([]int64 , 0 )
345- if err := db .WithTx (ctx , func (ctx context.Context ) error {
333+ return db .WithTx (ctx , func (ctx context.Context ) error {
346334 repoIDs , err := issues_model .GetOrphanedIssueRepoIDs (ctx )
347335 if err != nil {
348336 return err
349337 }
350338 for i := range repoIDs {
351- deletions , err := DeleteIssuesByRepoID (ctx , repoIDs [i ], true )
352- if err != nil {
339+ if err := DeleteIssuesByRepoID (ctx , repoIDs [i ], true ); err != nil {
353340 return err
354341 }
355- toBeCleanedDeletions = append (toBeCleanedDeletions , deletions ... )
356342 }
357343 return nil
358- }); err != nil {
359- return err
360- }
361- storagecleanup .AddDeletionsToCleanQueue (ctx , toBeCleanedDeletions )
362- return nil
344+ })
363345}
364346
365347// DeleteIssuesByRepoID deletes issues by repositories id
366- func DeleteIssuesByRepoID (ctx context.Context , repoID int64 , deleteAttachments bool ) ([]int64 , error ) {
367- toBeCleanedDeletions := make ([]int64 , 0 )
348+ func DeleteIssuesByRepoID (ctx context.Context , repoID int64 , deleteAttachments bool ) error {
368349 for {
369350 issues := make ([]* issues_model.Issue , 0 , db .DefaultMaxInSize )
370351 if err := db .GetEngine (ctx ).
371352 Where ("repo_id = ?" , repoID ).
372353 OrderBy ("id" ).
373354 Limit (db .DefaultMaxInSize ).
374355 Find (& issues ); err != nil {
375- return nil , err
356+ return err
376357 }
377358
378359 if len (issues ) == 0 {
379360 break
380361 }
381362
382363 for _ , issue := range issues {
383- deletions , err := deleteIssue (ctx , issue , deleteAttachments )
384- if err != nil {
385- return nil , fmt .Errorf ("deleteIssue [issue_id: %d]: %w" , issue .ID , err )
364+ if err := deleteIssue (ctx , issue , deleteAttachments ); err != nil {
365+ return fmt .Errorf ("deleteIssue [issue_id: %d]: %w" , issue .ID , err )
386366 }
387- toBeCleanedDeletions = append (toBeCleanedDeletions , deletions ... )
388367 }
389368 }
390369
391- return toBeCleanedDeletions , nil
370+ return nil
392371}
0 commit comments