Skip to content
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

Improve: filter Swagger input files before loading them, to improve speed of generator #1842

Closed
Porges opened this issue Sep 28, 2021 · 6 comments
Milestone

Comments

@Porges
Copy link
Member

Porges commented Sep 28, 2021

I think with functions like:

func (t *TypeMatcher) AppliesToAnyTypesInPackage(p astmodel.LocalPackageReference) bool {
	return t.groupMatches(p.Group()) && t.versionMatches(p.Version())
}

func (t *TypeMatcher) AppliesToWholePackage(p astmodel.LocalPackageReference) bool {
	return t.groupMatches(p.Group()) && t.versionMatches(p.Version()) && t.Name == ""
}

We can write a function like:

func fileShouldBeIncluded(filters []*config.TypeFilter, exportFilters []*config.ExportFilter, localPackage astmodel.LocalPackageReference) (string, bool) {
	for _, filter := range filters {
		if filter.Action == config.TypeFilterInclude && filter.AppliesToAnyTypesInPackage(localPackage) {
			return filter.Because, true
		}

		if filter.Action == config.TypeFilterPrune && filter.AppliesToWholePackage(localPackage) {
			return filter.Because, false
		}
	}

	for _, exportFilter := range exportFilters {
		if exportFilter.Action == config.ExportFilterInclude && exportFilter.AppliesToAnyTypesInPackage(localPackage) {
			return exportFilter.Because, true
		}

		if exportFilter.Action == config.ExportFilterExclude && exportFilter.AppliesToWholePackage(localPackage) {
			return exportFilter.Because, false
		}
	}

	// default to true
	return "", true
}

Logic to be checked!

Driving code:

			group := jsonast.SwaggerGroupRegex.FindString(filePath)
			version := strings.Trim(swaggerVersionRegex.FindString(filePath), "/")
			localPackage := astmodel.MakeLocalPackageReference(
				packagePrefix,
				group,
				version,
			)

			because, include := fileShouldBeIncluded(filters, exportFilters, localPackage)
			if !include {
				klog.V(3).Infof("Skipping whole file %q, because: %s", filePath, because)
				return nil
			}
@theunrepentantgeek
Copy link
Member

We still see value in this.

@theunrepentantgeek
Copy link
Member

Still interested.

@matthchr
Copy link
Member

Could we do something based purely on group, even if we can't be more fine-grained than that?

@theunrepentantgeek
Copy link
Member

We still want to do something to reduce the workload of the generator.

@matthchr
Copy link
Member

We're still interested in this, although we have done some in this space to speed things up (@theunrepentantgeek thinks by group).

@theunrepentantgeek
Copy link
Member

Sufficiently addressed by #3803

@github-project-automation github-project-automation bot moved this from Backlog to Recently Completed in Azure Service Operator Roadmap Feb 23, 2024
@matthchr matthchr moved this from Recently Completed to Ready for Release in Azure Service Operator Roadmap Feb 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Development

No branches or pull requests

3 participants