Fetch models right after signing in (#35711)
This uses the `current_user` watch in the `UserStore` instead of looping every 100ms in order to detect if the user had signed in. We are changing this because we noticed it was causing the deterministic executor in tests to never detect a "parking with nothing left to run" situation. This seems better in production as well, especially for users who never sign in. /cc @maxdeviant Release Notes: - N/A Co-authored-by: Ben Brandt <benjamin.j.brandt@gmail.com>
This commit is contained in:
parent
0dad4b7a41
commit
53a3270410
1 changed files with 7 additions and 14 deletions
|
@ -136,6 +136,7 @@ impl State {
|
||||||
cx: &mut Context<Self>,
|
cx: &mut Context<Self>,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
let refresh_llm_token_listener = RefreshLlmTokenListener::global(cx);
|
let refresh_llm_token_listener = RefreshLlmTokenListener::global(cx);
|
||||||
|
let mut current_user = user_store.read(cx).watch_current_user();
|
||||||
Self {
|
Self {
|
||||||
client: client.clone(),
|
client: client.clone(),
|
||||||
llm_api_token: LlmApiToken::default(),
|
llm_api_token: LlmApiToken::default(),
|
||||||
|
@ -151,22 +152,14 @@ impl State {
|
||||||
let (client, llm_api_token) = this
|
let (client, llm_api_token) = this
|
||||||
.read_with(cx, |this, _cx| (client.clone(), this.llm_api_token.clone()))?;
|
.read_with(cx, |this, _cx| (client.clone(), this.llm_api_token.clone()))?;
|
||||||
|
|
||||||
loop {
|
while current_user.borrow().is_none() {
|
||||||
let is_authenticated = user_store
|
current_user.next().await;
|
||||||
.read_with(cx, |user_store, _cx| user_store.current_user().is_some())?;
|
|
||||||
if is_authenticated {
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
cx.background_executor()
|
let response =
|
||||||
.timer(Duration::from_millis(100))
|
Self::fetch_models(client.clone(), llm_api_token.clone()).await?;
|
||||||
.await;
|
this.update(cx, |this, cx| this.update_models(response, cx))?;
|
||||||
}
|
anyhow::Ok(())
|
||||||
|
|
||||||
let response = Self::fetch_models(client, llm_api_token).await?;
|
|
||||||
this.update(cx, |this, cx| {
|
|
||||||
this.update_models(response, cx);
|
|
||||||
})
|
|
||||||
})
|
})
|
||||||
.await
|
.await
|
||||||
.context("failed to fetch Zed models")
|
.context("failed to fetch Zed models")
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue