MCPcopy Create free account
hub / github.com/erans/pgsqlite / get_or_cache_connection

Method get_or_cache_connection

src/query/executor.rs:159–179  ·  view source on GitHub ↗

Get cached connection or fetch and cache it

(
        session: &Arc<SessionState>,
        db: &Arc<DbHandler>
    )

Source from the content-addressed store, hash-verified

157impl QueryExecutor {
158 /// Get cached connection or fetch and cache it
159 async fn get_or_cache_connection(
160 session: &Arc<SessionState>,
161 db: &Arc<DbHandler>
162 ) -> Option<Arc<parking_lot::Mutex<rusqlite::Connection>>> {
163 // First check if we have a cached connection
164 if let Some(cached) = session.get_cached_connection() {
165 // debug!("Using cached connection for session {}", session.id);
166 return Some(cached);
167 }
168
169 // Try to get connection from manager and cache it
170 // debug!("Connection not cached for session {}, fetching from manager", session.id);
171 if let Some(conn_arc) = db.connection_manager().get_connection_arc(&session.id) {
172 session.cache_connection(conn_arc.clone());
173 // debug!("Cached connection for session {}", session.id);
174 Some(conn_arc)
175 } else {
176 // debug!("No connection found for session {}", session.id);
177 None
178 }
179 }
180 pub async fn execute_query<T>(
181 framed: &mut Framed<T, crate::protocol::PostgresCodec>,
182 db: &Arc<DbHandler>,

Callers

nothing calls this directly

Calls 5

get_cached_connectionMethod · 0.80
get_connection_arcMethod · 0.80
connection_managerMethod · 0.80
cache_connectionMethod · 0.80
cloneMethod · 0.45

Tested by

no test coverage detected