-
-
Notifications
You must be signed in to change notification settings - Fork 5.9k
when using rules to delete packages, remove unclean bugs #34632
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
Open
anthony-zh
wants to merge
6
commits into
go-gitea:main
Choose a base branch
from
anthony-zh:cleanup
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+34
−38
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
9011d6d
when using rules to delete packages, remove unclean bugs
25bc9b6
add cleanup test over 200
3bb2acd
test out version name
bc8f1e3
cleanup by rule error
277b9c5
lint error
d130dd6
Remove the db transaction and load all corresponding versions into me…
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -33,13 +33,7 @@ func CleanupTask(ctx context.Context, olderThan time.Duration) error { | |
} | ||
|
||
func ExecuteCleanupRules(outerCtx context.Context) error { | ||
ctx, committer, err := db.TxContext(outerCtx) | ||
if err != nil { | ||
return err | ||
} | ||
defer committer.Close() | ||
|
||
err = packages_model.IterateEnabledCleanupRules(ctx, func(ctx context.Context, pcr *packages_model.PackageCleanupRule) error { | ||
return packages_model.IterateEnabledCleanupRules(outerCtx, func(ctx context.Context, pcr *packages_model.PackageCleanupRule) error { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why the |
||
select { | ||
case <-outerCtx.Done(): | ||
return db.ErrCancelledf("While processing package cleanup rules") | ||
|
@@ -63,11 +57,17 @@ func ExecuteCleanupRules(outerCtx context.Context) error { | |
PackageID: p.ID, | ||
IsInternal: optional.Some(false), | ||
Sort: packages_model.SortCreatedDesc, | ||
Paginator: db.NewAbsoluteListOptions(pcr.KeepCount, 200), | ||
}) | ||
if err != nil { | ||
return fmt.Errorf("CleanupRule [%d]: SearchVersions failed: %w", pcr.ID, err) | ||
} | ||
if pcr.KeepCount > 0 { | ||
if pcr.KeepCount < len(pvs) { | ||
pvs = pvs[pcr.KeepCount:] | ||
} else { | ||
pvs = nil | ||
} | ||
} | ||
versionDeleted := false | ||
for _, pv := range pvs { | ||
if pcr.Type == packages_model.TypeContainer { | ||
|
@@ -78,35 +78,30 @@ func ExecuteCleanupRules(outerCtx context.Context) error { | |
continue | ||
} | ||
} | ||
|
||
toMatch := pv.LowerVersion | ||
if pcr.MatchFullName { | ||
toMatch = p.LowerName + "/" + pv.LowerVersion | ||
} | ||
|
||
if pcr.KeepPatternMatcher != nil && pcr.KeepPatternMatcher.MatchString(toMatch) { | ||
log.Debug("Rule[%d]: keep '%s/%s' (keep pattern)", pcr.ID, p.Name, pv.Version) | ||
continue | ||
} | ||
if pv.CreatedUnix.AsLocalTime().After(olderThan) { | ||
log.Debug("Rule[%d]: keep '%s/%s' (remove days)", pcr.ID, p.Name, pv.Version) | ||
log.Debug("Rule[%d]: keep '%s/%s' (remove days) %v", pcr.ID, p.Name, pv.Version, pv.CreatedUnix.FormatDate()) | ||
continue | ||
} | ||
if pcr.RemovePatternMatcher != nil && !pcr.RemovePatternMatcher.MatchString(toMatch) { | ||
log.Debug("Rule[%d]: keep '%s/%s' (remove pattern)", pcr.ID, p.Name, pv.Version) | ||
continue | ||
} | ||
|
||
log.Debug("Rule[%d]: remove '%s/%s'", pcr.ID, p.Name, pv.Version) | ||
|
||
if err := packages_service.DeletePackageVersionAndReferences(ctx, pv); err != nil { | ||
return fmt.Errorf("CleanupRule [%d]: DeletePackageVersionAndReferences failed: %w", pcr.ID, err) | ||
log.Error("CleanupRule [%d]: DeletePackageVersionAndReferences failed: %w", pcr.ID, err) | ||
continue | ||
} | ||
|
||
versionDeleted = true | ||
anyVersionDeleted = true | ||
} | ||
|
||
if versionDeleted { | ||
if pcr.Type == packages_model.TypeCargo { | ||
owner, err := user_model.GetUserByID(ctx, pcr.OwnerID) | ||
|
@@ -148,11 +143,6 @@ func ExecuteCleanupRules(outerCtx context.Context) error { | |
} | ||
return nil | ||
}) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
return committer.Commit() | ||
} | ||
|
||
func CleanupExpiredData(outerCtx context.Context, olderThan time.Duration) error { | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why the behavior is changed? The root problem is how we should treat the "count": does it have a clear meaning like "the total count in database"?