Skip to content

Commit 266a217

Browse files
committed
use arc for schema cache
1 parent c55a2d8 commit 266a217

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

crates/pgt_workspace/src/workspace/server.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -372,7 +372,7 @@ impl Workspace for WorkspaceServer {
372372
{
373373
let path_clone = params.path.clone();
374374
let schema_cache = self.schema_cache.load(pool.clone())?;
375-
let schema_cache_arc = Arc::new(schema_cache.as_ref().clone());
375+
let schema_cache_arc = schema_cache.get_arc();
376376
let input = parser.iter(AsyncDiagnosticsMapper).collect::<Vec<_>>();
377377
// sorry for the ugly code :(
378378
let async_results = run_async(async move {

crates/pgt_workspace/src/workspace/server/schema_cache_manager.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use std::sync::{RwLock, RwLockReadGuard};
1+
use std::sync::{Arc, RwLock, RwLockReadGuard};
22

33
use pgt_schema_cache::SchemaCache;
44
use sqlx::PgPool;
@@ -21,6 +21,10 @@ impl<'a> SchemaCacheHandle<'a> {
2121
pub(crate) fn wrap(inner: RwLockReadGuard<'a, SchemaCacheManagerInner>) -> Self {
2222
Self { inner }
2323
}
24+
25+
pub fn get_arc(&self) -> Arc<SchemaCache> {
26+
Arc::clone(&self.inner.cache)
27+
}
2428
}
2529

2630
impl AsRef<SchemaCache> for SchemaCacheHandle<'_> {
@@ -31,7 +35,7 @@ impl AsRef<SchemaCache> for SchemaCacheHandle<'_> {
3135

3236
#[derive(Default)]
3337
pub(crate) struct SchemaCacheManagerInner {
34-
cache: SchemaCache,
38+
cache: Arc<SchemaCache>,
3539
conn_str: String,
3640
}
3741

@@ -62,7 +66,7 @@ impl SchemaCacheManager {
6266

6367
// Double-check that we still need to refresh (another thread might have done it)
6468
if new_conn_str != inner.conn_str {
65-
inner.cache = refreshed;
69+
inner.cache = Arc::new(refreshed);
6670
inner.conn_str = new_conn_str;
6771
tracing::info!("Refreshed connection.");
6872
}

0 commit comments

Comments
 (0)