perf: parallelize provider resolution and eagerly init SQLite pool (#8899)
Signed-off-by: Matt Toohey <contact@matttoohey.com> Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -957,6 +957,13 @@ impl GooseAcpAgent {
|
|||||||
goose_platform: GoosePlatform,
|
goose_platform: GoosePlatform,
|
||||||
) -> Result<Self> {
|
) -> Result<Self> {
|
||||||
let session_manager = Arc::new(SessionManager::new(data_dir));
|
let session_manager = Arc::new(SessionManager::new(data_dir));
|
||||||
|
|
||||||
|
// Eagerly initialize the SQLite pool so it's ready when providers/sessions need it.
|
||||||
|
let storage_clone = session_manager.storage().clone();
|
||||||
|
tokio::spawn(async move {
|
||||||
|
let _ = storage_clone.pool().await;
|
||||||
|
});
|
||||||
|
|
||||||
let thread_manager = Arc::new(crate::session::ThreadManager::new(
|
let thread_manager = Arc::new(crate::session::ThreadManager::new(
|
||||||
session_manager.storage().clone(),
|
session_manager.storage().clone(),
|
||||||
));
|
));
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ use super::canonical::{map_provider_name, map_to_canonical_model, CanonicalModel
|
|||||||
use crate::config::declarative_providers::{DeclarativeProviderConfig, ProviderEngine};
|
use crate::config::declarative_providers::{DeclarativeProviderConfig, ProviderEngine};
|
||||||
use crate::config::Config;
|
use crate::config::Config;
|
||||||
use crate::session::session_manager::SessionStorage;
|
use crate::session::session_manager::SessionStorage;
|
||||||
use anyhow::Result;
|
use anyhow::{Context, Result};
|
||||||
use chrono::{DateTime, Duration, Utc};
|
use chrono::{DateTime, Duration, Utc};
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use sha2::{Digest, Sha256};
|
use sha2::{Digest, Sha256};
|
||||||
@@ -307,9 +307,18 @@ impl ProviderInventoryService {
|
|||||||
|
|
||||||
pub async fn entries(&self, provider_ids: &[String]) -> Result<Vec<ProviderInventoryEntry>> {
|
pub async fn entries(&self, provider_ids: &[String]) -> Result<Vec<ProviderInventoryEntry>> {
|
||||||
let ids = self.resolve_provider_ids(provider_ids).await;
|
let ids = self.resolve_provider_ids(provider_ids).await;
|
||||||
let mut entries = Vec::with_capacity(ids.len());
|
let handles: Vec<_> = ids
|
||||||
for provider_id in ids {
|
.into_iter()
|
||||||
if let Some(entry) = self.entry_for_provider(&provider_id).await? {
|
.map(|id| {
|
||||||
|
let this = self.clone();
|
||||||
|
tokio::spawn(async move { this.entry_for_provider(&id).await })
|
||||||
|
})
|
||||||
|
.collect();
|
||||||
|
let results = futures::future::join_all(handles).await;
|
||||||
|
let mut entries = Vec::with_capacity(results.len());
|
||||||
|
for result in results {
|
||||||
|
let inner = result.context("provider inventory task panicked")?;
|
||||||
|
if let Some(entry) = inner? {
|
||||||
entries.push(entry);
|
entries.push(entry);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user