You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

v112.go 998 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. // Copyright 2019 The Gitea Authors. All rights reserved.
  2. // Use of this source code is governed by a MIT-style
  3. // license that can be found in the LICENSE file.
  4. package migrations
  5. import (
  6. "code.gitea.io/gitea/modules/storage"
  7. "xorm.io/builder"
  8. "xorm.io/xorm"
  9. )
  10. func removeAttachmentMissedRepo(x *xorm.Engine) error {
  11. type Attachment struct {
  12. UUID string `xorm:"uuid"`
  13. }
  14. var start int
  15. attachments := make([]*Attachment, 0, 50)
  16. for {
  17. err := x.Select("uuid").Where(builder.NotIn("release_id", builder.Select("id").From("`release`"))).
  18. And("release_id > 0").
  19. OrderBy("id").Limit(50, start).Find(&attachments)
  20. if err != nil {
  21. return err
  22. }
  23. for i := 0; i < len(attachments); i++ {
  24. storage.Attachments.Delete(relativePath(attachments[i].UUID))
  25. }
  26. if len(attachments) < 50 {
  27. break
  28. }
  29. start += 50
  30. attachments = attachments[:0]
  31. }
  32. _, err := x.Exec("DELETE FROM attachment WHERE release_id > 0 AND release_id NOT IN (SELECT id FROM `release`)")
  33. return err
  34. }