dikhan / terraform-provider-openapi

OpenAPI Terraform Provider that configures itself at runtime with the resources exposed by the service provider (defined in a swagger file)
Apache License 2.0
275 stars 48 forks source link

Inefficient execution of certain methods in SpecV2Resource #260

Closed dikhan closed 4 years ago

dikhan commented 4 years ago

Is your feature request related to a problem?

As a OpenAPI Terraform plugin user
I want the plugin to cache certain code that is currently being executed multiple times
So that the plugin executes faster

Describe the solution you'd like

Currently the implementation of SpecResource SpecV2Resource does a lot of processing behind the scenes when certain methods are called (eg: GetResourceSchema, GetParentResourceInfo or getResourcePath). These methods are called multiple times in various places of the code making the plugin process the same code redundantly causing the total plugin execution time to increase significantly for each resource execution. The following shows where the methods are being used for the reference at the moment:

Acceptance criteria

Scenario: GetResourceSchema() creates a SpecSchemaDefinition the first time is executed, subsequent calls will get the cached object
Given the openapi_v2_resource.go file
When the GetResourceSchema() method is called 
Then the first time the method is executed it should cache the generated SpecSchemaDefinition and store it in a local private property of SpecV2Resource (eg: specSchemaDefinitionCached). Hence, the next time the method is executed the cached object would be returned instead
Scenario: GetParentResourceInfo() creates a ParentResourceInfo the first time is executed, subsequent calls will get the cached object
Given the openapi_v2_resource.go file
When the GetParentResourceInfo() method is called 
Then the first time the method is executed it should cache the generated ParentResourceInfo and store it in a local private property of SpecV2Resource (eg: parentResourceInfoCached). Hence, the next time the method is executed the cached object would be returned instead
Scenario: getResourcePath() creates a path with the ids resolved the first time is executed, subsequent calls will get the cached object
Given the openapi_v2_resource.go file
When the getResourcePath() method is called 
Then the first time the method is executed it should cache the generated path with the ids resolved and store it in a local private property of SpecV2Resource (eg: resolvedPathCached). Hence, the next time the method is executed the cached object would be returned instead

Describe alternatives you've considered

A clear and concise description of any alternative solutions or features you've considered.

Additional context

Add any other context or screenshots about the feature request here.

Checklist (for admin only)

Don't forget to go through the checklist to make sure the issue is created properly: