forked from Shiloh/githaven
Simplify the LFS GC logger usage (#25717)
Remove unnecessary `if opts.Logger != nil` checks. * For "CLI doctor" mode, output to the console's "logger.Info". * For "Web Task" mode, output to the default "logger.Debug", to avoid flooding the server's log in a busy production instance. Co-authored-by: Giteabot <teabot@gitea.io>
This commit is contained in:
parent
f03d95f0a9
commit
f0bde0e4f9
@ -31,8 +31,8 @@ func garbageCollectLFSCheck(ctx context.Context, logger log.Logger, autofix bool
|
|||||||
}
|
}
|
||||||
|
|
||||||
if err := repository.GarbageCollectLFSMetaObjects(ctx, repository.GarbageCollectLFSMetaObjectsOptions{
|
if err := repository.GarbageCollectLFSMetaObjects(ctx, repository.GarbageCollectLFSMetaObjectsOptions{
|
||||||
Logger: logger,
|
LogDetail: logger.Info,
|
||||||
AutoFix: autofix,
|
AutoFix: autofix,
|
||||||
// Only attempt to garbage collect lfs meta objects older than a week as the order of git lfs upload
|
// Only attempt to garbage collect lfs meta objects older than a week as the order of git lfs upload
|
||||||
// and git object upload is not necessarily guaranteed. It's possible to imagine a situation whereby
|
// and git object upload is not necessarily guaranteed. It's possible to imagine a situation whereby
|
||||||
// an LFS object is uploaded but the git branch is not uploaded immediately, or there are some rapid
|
// an LFS object is uploaded but the git branch is not uploaded immediately, or there are some rapid
|
||||||
|
@ -19,7 +19,7 @@ import (
|
|||||||
|
|
||||||
// GarbageCollectLFSMetaObjectsOptions provides options for GarbageCollectLFSMetaObjects function
|
// GarbageCollectLFSMetaObjectsOptions provides options for GarbageCollectLFSMetaObjects function
|
||||||
type GarbageCollectLFSMetaObjectsOptions struct {
|
type GarbageCollectLFSMetaObjectsOptions struct {
|
||||||
Logger log.Logger
|
LogDetail func(format string, v ...any)
|
||||||
AutoFix bool
|
AutoFix bool
|
||||||
OlderThan time.Time
|
OlderThan time.Time
|
||||||
UpdatedLessRecentlyThan time.Time
|
UpdatedLessRecentlyThan time.Time
|
||||||
@ -32,10 +32,12 @@ func GarbageCollectLFSMetaObjects(ctx context.Context, opts GarbageCollectLFSMet
|
|||||||
log.Trace("Doing: GarbageCollectLFSMetaObjects")
|
log.Trace("Doing: GarbageCollectLFSMetaObjects")
|
||||||
defer log.Trace("Finished: GarbageCollectLFSMetaObjects")
|
defer log.Trace("Finished: GarbageCollectLFSMetaObjects")
|
||||||
|
|
||||||
|
if opts.LogDetail == nil {
|
||||||
|
opts.LogDetail = log.Debug
|
||||||
|
}
|
||||||
|
|
||||||
if !setting.LFS.StartServer {
|
if !setting.LFS.StartServer {
|
||||||
if opts.Logger != nil {
|
opts.LogDetail("LFS support is disabled")
|
||||||
opts.Logger.Info("LFS support is disabled")
|
|
||||||
}
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -54,21 +56,17 @@ func GarbageCollectLFSMetaObjects(ctx context.Context, opts GarbageCollectLFSMet
|
|||||||
|
|
||||||
// GarbageCollectLFSMetaObjectsForRepo garbage collects LFS objects for a specific repository
|
// GarbageCollectLFSMetaObjectsForRepo garbage collects LFS objects for a specific repository
|
||||||
func GarbageCollectLFSMetaObjectsForRepo(ctx context.Context, repo *repo_model.Repository, opts GarbageCollectLFSMetaObjectsOptions) error {
|
func GarbageCollectLFSMetaObjectsForRepo(ctx context.Context, repo *repo_model.Repository, opts GarbageCollectLFSMetaObjectsOptions) error {
|
||||||
if opts.Logger != nil {
|
opts.LogDetail("Checking %-v", repo)
|
||||||
opts.Logger.Info("Checking %-v", repo)
|
|
||||||
}
|
|
||||||
total, orphaned, collected, deleted := int64(0), 0, 0, 0
|
total, orphaned, collected, deleted := int64(0), 0, 0, 0
|
||||||
if opts.Logger != nil {
|
defer func() {
|
||||||
defer func() {
|
if orphaned == 0 {
|
||||||
if orphaned == 0 {
|
opts.LogDetail("Found %d total LFSMetaObjects in %-v", total, repo)
|
||||||
opts.Logger.Info("Found %d total LFSMetaObjects in %-v", total, repo)
|
} else if !opts.AutoFix {
|
||||||
} else if !opts.AutoFix {
|
opts.LogDetail("Found %d/%d orphaned LFSMetaObjects in %-v", orphaned, total, repo)
|
||||||
opts.Logger.Info("Found %d/%d orphaned LFSMetaObjects in %-v", orphaned, total, repo)
|
} else {
|
||||||
} else {
|
opts.LogDetail("Collected %d/%d orphaned/%d total LFSMetaObjects in %-v. %d removed from storage.", collected, orphaned, total, repo, deleted)
|
||||||
opts.Logger.Info("Collected %d/%d orphaned/%d total LFSMetaObjects in %-v. %d removed from storage.", collected, orphaned, total, repo, deleted)
|
}
|
||||||
}
|
}()
|
||||||
}()
|
|
||||||
}
|
|
||||||
|
|
||||||
gitRepo, err := git.OpenRepository(ctx, repo.RepoPath())
|
gitRepo, err := git.OpenRepository(ctx, repo.RepoPath())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -129,9 +127,7 @@ func GarbageCollectLFSMetaObjectsForRepo(ctx context.Context, repo *repo_model.R
|
|||||||
})
|
})
|
||||||
|
|
||||||
if err == errStop {
|
if err == errStop {
|
||||||
if opts.Logger != nil {
|
opts.LogDetail("Processing stopped at %d total LFSMetaObjects in %-v", total, repo)
|
||||||
opts.Logger.Info("Processing stopped at %d total LFSMetaObjects in %-v", total, repo)
|
|
||||||
}
|
|
||||||
return nil
|
return nil
|
||||||
} else if err != nil {
|
} else if err != nil {
|
||||||
return err
|
return err
|
||||||
|
Loading…
Reference in New Issue
Block a user