Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update repository size on cron gc task #15177

Merged
merged 6 commits into from
Mar 28, 2021
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
zeripath marked this conversation as resolved.
Show resolved Hide resolved
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)
zeripath marked this conversation as resolved.
Show resolved Hide resolved
}

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