Skip to content

Commit

Permalink
Update repository size on cron gc task
Browse files Browse the repository at this point in the history
git gc cron could change the size of the repository therefore we should update the
size of the repo stored in our database.

Also significantly improve the efficiency of counting lfs associated with the
repository

Fix #14682

Signed-off-by: Andrew Thornton <art27@cantab.net>
  • Loading branch information
zeripath committed Mar 27, 2021
1 parent 6b836ac commit b7f0def
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
7 changes: 2 additions & 5 deletions models/repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -740,15 +740,12 @@ func (repo *Repository) updateSize(e Engine) error {
return fmt.Errorf("updateSize: %v", err)
}

objs, err := repo.GetLFSMetaObjects(-1, 0)
lfsSize, err := e.Where("repository_id = ?", repo.ID).SumInt(new(LFSMetaObject), "size")
if err != nil {
return fmt.Errorf("updateSize: GetLFSMetaObjects: %v", err)
}
for _, obj := range objs {
size += obj.Size
}

repo.Size = size
repo.Size = size + lfsSize
_, err = e.ID(repo.ID).Cols("size").Update(repo)
return err
}
Expand Down
11 changes: 11 additions & 0 deletions modules/repository/check.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,17 @@ func GitGcRepos(ctx context.Context, timeout time.Duration, args ...string) erro
}
return fmt.Errorf("Repository garbage collection failed in repo: %s: Error: %v", repo.FullName(), err)
}

// Now update the size of the repository
if err := repo.UpdateSize(models.DefaultDBContext()); err != nil {
log.Error("Updating size as part of garbage collection failed for %v. Stdout: %s\nError: %v", repo, stdout, err)
desc := fmt.Sprintf("Updating size as part of garbage collection failed for %s. Stdout: %s\nError: %v", repo.RepoPath(), stdout, err)
if err = models.CreateRepositoryNotice(desc); err != nil {
log.Error("CreateRepositoryNotice: %v", err)
}
return fmt.Errorf("Updating size as part of garbage collection failed in repo: %s: Error: %v", repo.FullName(), err)
}

return nil
},
); err != nil {
Expand Down

0 comments on commit b7f0def

Please sign in to comment.