-
-
Notifications
You must be signed in to change notification settings - Fork 6.4k
Fix bug when do LFS GC #36500
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
Merged
+101
−23
Merged
Fix bug when do LFS GC #36500
Changes from 3 commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
c8259c6
Fix bug when do LFS GC
lunny 2be938c
correct copyright year
lunny 6bf7e47
Fix test
lunny 1bb4b9a
Follow reviews
lunny e6ad8bf
improvement
lunny aaf9470
remove unnecessary change
lunny f400574
remove unnecessary change
lunny 0d9d5f8
Fix bug
lunny e722d8c
Merge branch 'main' into lunny/fix_lfs_gc
lunny b2879d7
Merge branch 'main' into lunny/fix_lfs_gc
lunny 7792f81
Merge branch 'main' into lunny/fix_lfs_gc
lunny 0fd0be6
Update services/repository/lfs_test.go
lunny d50a740
Fix test
lunny 9dad02d
Merge branch 'main' into lunny/fix_lfs_gc
lunny 81ee160
Merge branch 'lunny/fix_lfs_gc' of github.com:lunny/gitea into lunny/…
lunny e3e20f6
Merge branch 'main' into lunny/fix_lfs_gc
lunny 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,61 @@ | ||
| // Copyright 2026 The Gitea Authors. All rights reserved. | ||
| // SPDX-License-Identifier: MIT | ||
|
|
||
| package git_test | ||
|
|
||
| import ( | ||
| "bytes" | ||
| "context" | ||
| "strconv" | ||
| "testing" | ||
| "time" | ||
|
|
||
| "code.gitea.io/gitea/models/db" | ||
| git_model "code.gitea.io/gitea/models/git" | ||
| repo_model "code.gitea.io/gitea/models/repo" | ||
| "code.gitea.io/gitea/models/unittest" | ||
| "code.gitea.io/gitea/modules/lfs" | ||
| "code.gitea.io/gitea/modules/setting" | ||
| "code.gitea.io/gitea/modules/test" | ||
| "code.gitea.io/gitea/modules/timeutil" | ||
|
|
||
| "github.com/stretchr/testify/assert" | ||
| ) | ||
|
|
||
| func TestIterateLFSMetaObjectsForRepoUpdatesDoNotSkip(t *testing.T) { | ||
| unittest.PrepareTestEnv(t) | ||
|
|
||
| ctx := t.Context() | ||
| repo, err := repo_model.GetRepositoryByOwnerAndName(ctx, "user2", "repo1") | ||
| assert.NoError(t, err) | ||
|
|
||
| test.MockVariableValue(&setting.Database.IterateBufferSize, 1) | ||
lunny marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| created := make([]*git_model.LFSMetaObject, 0, 3) | ||
| for i := range 3 { | ||
| content := []byte("gitea-lfs-" + strconv.Itoa(i)) | ||
| pointer, err := lfs.GeneratePointer(bytes.NewReader(content)) | ||
| assert.NoError(t, err) | ||
|
|
||
| meta, err := git_model.NewLFSMetaObject(ctx, repo.ID, pointer) | ||
| assert.NoError(t, err) | ||
| created = append(created, meta) | ||
| } | ||
|
|
||
| iterated := make([]int64, 0, len(created)) | ||
| cutoff := time.Now().Add(24 * time.Hour) | ||
| iterErr := git_model.IterateLFSMetaObjectsForRepo(ctx, repo.ID, func(ctx context.Context, meta *git_model.LFSMetaObject, count int64) error { | ||
| iterated = append(iterated, meta.ID) | ||
| _, err := db.GetEngine(ctx).ID(meta.ID).Cols("updated_unix").Update(&git_model.LFSMetaObject{ | ||
| UpdatedUnix: timeutil.TimeStamp(time.Now().Unix()), | ||
| }) | ||
| return err | ||
| }, &git_model.IterateLFSMetaObjectsForRepoOptions{ | ||
| OlderThan: timeutil.TimeStamp(cutoff.Unix()), | ||
| UpdatedLessRecentlyThan: timeutil.TimeStamp(cutoff.Unix()), | ||
| }) | ||
| assert.NoError(t, iterErr) | ||
|
|
||
| expected := []int64{created[0].ID, created[1].ID, created[2].ID} | ||
| assert.Equal(t, expected, iterated) | ||
| } | ||
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
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.