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.

repo_indexer.go 1.2 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. // Copyright 2017 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 models
  5. // RepoIndexerStatus status of a repo's entry in the repo indexer
  6. // For now, implicitly refers to default branch
  7. type RepoIndexerStatus struct {
  8. ID int64 `xorm:"pk autoincr"`
  9. RepoID int64 `xorm:"INDEX"`
  10. CommitSha string `xorm:"VARCHAR(40)"`
  11. }
  12. // GetIndexerStatus loads repo codes indxer status
  13. func (repo *Repository) GetIndexerStatus() error {
  14. if repo.IndexerStatus != nil {
  15. return nil
  16. }
  17. status := &RepoIndexerStatus{RepoID: repo.ID}
  18. has, err := x.Get(status)
  19. if err != nil {
  20. return err
  21. } else if !has {
  22. status.CommitSha = ""
  23. }
  24. repo.IndexerStatus = status
  25. return nil
  26. }
  27. // UpdateIndexerStatus updates indexer status
  28. func (repo *Repository) UpdateIndexerStatus(sha string) error {
  29. if err := repo.GetIndexerStatus(); err != nil {
  30. return err
  31. }
  32. if len(repo.IndexerStatus.CommitSha) == 0 {
  33. repo.IndexerStatus.CommitSha = sha
  34. _, err := x.Insert(repo.IndexerStatus)
  35. return err
  36. }
  37. repo.IndexerStatus.CommitSha = sha
  38. _, err := x.ID(repo.IndexerStatus.ID).Cols("commit_sha").
  39. Update(repo.IndexerStatus)
  40. return err
  41. }