NobodyXu commented on code in PR #2192:
URL:
https://github.com/apache/incubator-opendal/pull/2192#discussion_r1186714828
##########
core/src/services/sftp/backend.rs:
##########
@@ -465,43 +441,133 @@ impl Accessor for SftpBackend {
return Err(e.into());
}
}
- };
- let dir = dir.read_dir().await?;
+ }
+ .read_dir();
Ok((
RpList::default(),
- SftpPager::new(dir.into_inner(), path.to_owned(), args.limit()),
+ SftpPager::new(dir, path.to_owned(), args.limit()),
))
}
}
impl SftpBackend {
- async fn pool(&self) -> Result<&bb8::Pool<Manager>> {
- let pool = self
- .sftp
- .get_or_try_init(|| async {
- let manager = Manager {
- endpoint: self.endpoint.clone(),
- user: self.user.clone(),
- key: self.key.clone(),
- };
-
- bb8::Pool::builder().max_size(10).build(manager).await
+ async fn connect(&self) -> Result<&Sftp> {
+ let sftp = self
+ .client
+ .get_or_try_init(|| {
+ connect_sftp(
+ self.endpoint.clone(),
+ self.root.clone(),
+ self.user.clone(),
+ self.key.clone(),
+ self.known_hosts_strategy.clone(),
+ )
Review Comment:
`SftpBackend::connect` would only do some useful work on the first call.
However, the returned future from the closure passed to
`OnceCell::get_or_try_init` would increase size of `SftpBackend::connect` a lot
even if it's mostly unused.
Using `Box::pin` here fix the problem without much sacrifice of the
performance.
Since it would be only called once for the entire program, `Box`ing is
acceptable.
```suggestion
Box::pin(connect_sftp(
self.endpoint.clone(),
self.root.clone(),
self.user.clone(),
self.key.clone(),
self.known_hosts_strategy.clone(),
))
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]