Optimize 'refreshAccesses' to perform update without removing then adding#35702
Open
rossigee wants to merge 7 commits intogo-gitea:mainfrom
Open
Optimize 'refreshAccesses' to perform update without removing then adding#35702rossigee wants to merge 7 commits intogo-gitea:mainfrom
rossigee wants to merge 7 commits intogo-gitea:mainfrom
Conversation
rossigee
commented
Oct 19, 2025
- Optimize refreshAccesses with cross-comparison to minimize DB operations
- Fix db.Find syntax in refreshAccesses optimization
- Add test for refreshAccesses update path and fix db.Find syntax
Implemented the FIXME to perform cross-comparison between existing and desired accesses, reducing deletions, updates, and insertions to the minimum necessary. This improves performance for repositories with many users by avoiding bulk delete-all and re-insert-all.
Corrected the db.Find call to use builder.Eq for the condition instead of passing a bean, which was causing compilation or runtime errors.
- Fix db.Find syntax error by using db.GetEngine().Where().Find() instead of db.Find() with builder.Eq directly - Add TestRepository_RecalculateAccesses_UpdateMode to test the update optimization path when user access mode changes - Improves test coverage for refreshAccesses from 69.4% to 75.0% - Validates that access mode updates use UPDATE instead of DELETE+INSERT
lunny
reviewed
Oct 20, 2025
lunny
reviewed
Oct 20, 2025
lunny
reviewed
Oct 26, 2025
| has, err = db.GetEngine(t.Context()).Get(updatedAccess) | ||
| assert.NoError(t, err) | ||
| assert.True(t, has, "Access should still exist") | ||
| assert.Equal(t, newMode, updatedAccess.Mode, "Access mode should be updated to new collaboration mode") |
Member
There was a problem hiding this comment.
It's better to have another use case to remove this user's permission and have a test again.
wxiaoguang
reviewed
Oct 26, 2025
wxiaoguang
reviewed
Oct 26, 2025
wxiaoguang
reviewed
Oct 26, 2025
Comment on lines
+118
to
+121
| var toUpdate []struct { | ||
| UserID int64 | ||
| Mode perm.AccessMode | ||
| } |
Contributor
There was a problem hiding this comment.
It can reuse the Access struct, and it could be clearer for the code below
wxiaoguang
reviewed
Oct 26, 2025
| for userID, ua := range accessMap { | ||
| if ua.Mode < minMode && !ua.User.IsRestricted { | ||
| continue | ||
| // Should not have access |
Contributor
There was a problem hiding this comment.
The comment seems not right.
If I read correctly, it doesn't mean "Should not have access", but "default access" is enough?
If it really means "should not have access", why ua.User.IsRestricted is kept
Contributor
There was a problem hiding this comment.
I made a test:
- Add U1 as public repo's collaborator with "read" access
- Trigger "refreshAccesses"
- U1's "access" record is skipped
- U1 can still access the public repo because the repo is public
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.