Skip to content

Conversation

rossigee
Copy link

  • 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
@GiteaBot GiteaBot added the lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. label Oct 19, 2025
@github-actions github-actions bot added the modifies/go Pull requests that update Go code label Oct 19, 2025
@rossigee rossigee changed the title optimize access refresh clean Optimize 'refreshAccesses' to perform update without removing then adding Oct 19, 2025
@rossigee rossigee marked this pull request as ready for review October 19, 2025 07:24
@lunny lunny added the type/refactoring Existing code has been cleaned up. There should be no new functionality. label Oct 20, 2025
@lunny lunny added this to the 1.26.0 milestone Oct 20, 2025
}

// 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) {
Copy link
Member

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)
Copy link
Member

@lunny lunny Oct 20, 2025

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. modifies/go Pull requests that update Go code type/refactoring Existing code has been cleaned up. There should be no new functionality.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants