Skip to content

Do not list repositories if the repository filters are not regexes #354

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
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

JRBANCEL
Copy link
Contributor

Purpose of the PR
As explained in #353, listing all the repositories can possibly never complete, or with the workaround from that PR, it can still take hours in large ACRs.

The problem is that in a very common scenario (the repository not being a regex), there is absolutely no need to list the repositories in the first place.

This PR simply checks that none of the repository parts of the provided filters are regex and if that's the case, use those as repository names instead of calling the potentially very expensive GetAllRepositoryNames.

We use this in our ACRs with ACR tasks for each known large repositories like purge --filter '<REPOSITORY>:.*' and it is instantaneous instead of taking hours.

@JRBANCEL JRBANCEL force-pushed the jrbancel/bypass-listing-repositories branch from 6b7a2b1 to 9978f88 Compare October 23, 2024 19:02
@JRBANCEL
Copy link
Contributor Author

@Wwwsylvia, @estebanreyl, @northtyphoon, @sajayantony, @shizhMSFT, @wangxiaoxuan273, @wju-MSFT can someone PTAL?

@estebanreyl
Copy link
Contributor

This is a nice optimization. Sorry for the late response, I missed the original ping.

@JRBANCEL
Copy link
Contributor Author

@estebanreyl are you going to look at this? If not who can?

Copy link
Contributor

@estebanreyl estebanreyl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry my review never left pending accidentally. Overall lgtm, left a couple of minor adjustments to address.

var allRepoNames []string

// Bypass listing the repositories if there are no regex in the repository name filters
notRegexRegex := regexp2.MustCompile(`^[a-z0-9-\/]+$`, defaultRegexpOptions)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit. Regular characters are still considered a valid regex, however in this case a search is not necessary. In light of that and the fact that using notRegexRegex is a bit redundant, maybe check for if this is a single repo name? like isSingleRepoNameRegex?

if err != nil {
return nil, err
}
if !notRegex {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This creates an odd double negative. Following what I noted above, maybe use isSingleRepoName?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants