Skip to content

fix(pglt_workspace): lock #213

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 21, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions crates/pglt_lsp/src/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -267,8 +267,6 @@ impl Session {
skip: Vec::new(),
})?;

tracing::trace!("pglt diagnostics: {:#?}", result.diagnostics);

result
.diagnostics
.into_iter()
Expand All @@ -290,8 +288,6 @@ impl Session {
.collect()
};

tracing::Span::current().record("diagnostic_count", diagnostics.len());

self.client
.publish_diagnostics(url, diagnostics, Some(doc.version))
.await;
Expand Down
28 changes: 15 additions & 13 deletions crates/pglt_workspace/src/workspace/server/schema_cache_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,23 +42,25 @@ pub struct SchemaCacheManager {

impl SchemaCacheManager {
pub fn load(&self, pool: PgPool) -> Result<SchemaCacheHandle, WorkspaceError> {
let inner = self.inner.read().unwrap();

if pool_to_conn_str(&pool) == inner.conn_str {
Ok(SchemaCacheHandle::wrap(inner))
} else {
let new_conn_str = pool_to_conn_str(&pool);
let new_conn_str = pool_to_conn_str(&pool);

{
// return early if the connection string is the same
let inner = self.inner.read().unwrap();
if new_conn_str == inner.conn_str {
return Ok(SchemaCacheHandle::wrap(inner));
}
}
Comment on lines +47 to +53
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we wrap this into its own block so the lock is dropped after


let maybe_refreshed = run_async(async move { SchemaCache::load(&pool).await })?;
let refreshed = maybe_refreshed?;
let maybe_refreshed = run_async(async move { SchemaCache::load(&pool).await })?;
let refreshed = maybe_refreshed?;

let mut inner = self.inner.write().unwrap();
let mut inner = self.inner.write().unwrap();

inner.cache = refreshed;
inner.conn_str = new_conn_str;
inner.cache = refreshed;
inner.conn_str = new_conn_str;

Ok(SchemaCacheHandle::new(&self.inner))
}
Ok(SchemaCacheHandle::new(&self.inner))
}
}

Expand Down