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

Initialize state on first request. #31

Merged
merged 7 commits into from
Aug 23, 2024
Merged

Initialize state on first request. #31

merged 7 commits into from
Aug 23, 2024

Conversation

SamirTalwar
Copy link
Contributor

@SamirTalwar SamirTalwar commented Aug 22, 2024

We don't need state to successfully handle some requests, so let's not initialize it until we need it.

With these changes, requests to /capabilities, /schema, and /health will still succeed even if the state cannot be initialized.

This wraps the state in a OnceCell which is initialized on first use.

This changes the ConnectorSetup interface, and as such constitutes a breaking change.

We don't need state to successfully handle some requests, so let's not
initialize it until we need it.

This wraps the state in a `OnceCell` which is initialized on first use.

The `ConnectorSetup` has been split into two to achieve this, because
`ParseConfiguration` cannot be made into an object.
@SamirTalwar SamirTalwar requested review from soupi, danieljharvey and a team August 22, 2024 14:24
Comment on lines -153 to +152
configuration_dir: impl AsRef<Path> + Send,
configuration_dir: &Path,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This change allows ConnectorSetup to be "object-safe", which means we can put it in a Box<dyn ConnectorSetup>.

Copy link
Contributor

Choose a reason for hiding this comment

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

Aha! How did you find out? was there a clue in the error message?

I suppose this restriction actually makes sense since f(arg: impl T<X>) actually becomes f<Y>(arg: Y) where Y impl T<X>, and if generics are compiled using specialization/erasure rather than passing around a dictionary of trait methods.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I stared it, thought "worth a try", tried it, and it worked! 😛

Copy link
Contributor

@plcplc plcplc left a comment

Choose a reason for hiding this comment

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

Much better shape

@plcplc plcplc added this pull request to the merge queue Aug 23, 2024
Merged via the queue into main with commit e5a3c83 Aug 23, 2024
10 checks passed
@plcplc plcplc deleted the samirtalwar/lazy-state branch August 23, 2024 11:29
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.

3 participants