-
-
Notifications
You must be signed in to change notification settings - Fork 6.2k
Optimize 'refreshAccesses' to perform update without removing then adding #35702
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
base: main
Are you sure you want to change the base?
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
} | ||
|
||
// FIXME: do cross-comparison so reduce deletions and additions to the minimum? | ||
func refreshAccesses(ctx context.Context, repo *repo_model.Repository, accessMap map[int64]*userAccess) (err error) { |
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.
It would be better to add a comment to this function explaining how the access is refreshed.
}) | ||
} | ||
} | ||
delete(existingMap, userID) |
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.
Is this safe to do and it seems it's unnecessary to delete at the moment?