Record worktree extensions every 5 minutes
Co-Authored-By: Nathan Sobo <nathan@zed.dev>
This commit is contained in:
parent
f9e0fec396
commit
639cd71a3b
7 changed files with 151 additions and 125 deletions
|
@ -52,7 +52,7 @@ pub trait Db: Send + Sync {
|
|||
&self,
|
||||
project_id: ProjectId,
|
||||
worktree_id: u64,
|
||||
extensions: HashMap<String, usize>,
|
||||
extensions: HashMap<String, u32>,
|
||||
) -> Result<()>;
|
||||
|
||||
/// Get the file counts on the given project keyed by their worktree and extension.
|
||||
|
@ -506,7 +506,7 @@ impl Db for PostgresDb {
|
|||
&self,
|
||||
project_id: ProjectId,
|
||||
worktree_id: u64,
|
||||
extensions: HashMap<String, usize>,
|
||||
extensions: HashMap<String, u32>,
|
||||
) -> Result<()> {
|
||||
if extensions.is_empty() {
|
||||
return Ok(());
|
||||
|
@ -2255,7 +2255,7 @@ pub mod tests {
|
|||
background: Arc<Background>,
|
||||
pub users: Mutex<BTreeMap<UserId, User>>,
|
||||
pub projects: Mutex<BTreeMap<ProjectId, Project>>,
|
||||
pub worktree_extensions: Mutex<BTreeMap<(ProjectId, u64, String), usize>>,
|
||||
pub worktree_extensions: Mutex<BTreeMap<(ProjectId, u64, String), u32>>,
|
||||
pub orgs: Mutex<BTreeMap<OrgId, Org>>,
|
||||
pub org_memberships: Mutex<BTreeMap<(OrgId, UserId), bool>>,
|
||||
pub channels: Mutex<BTreeMap<ChannelId, Channel>>,
|
||||
|
@ -2442,7 +2442,7 @@ pub mod tests {
|
|||
&self,
|
||||
project_id: ProjectId,
|
||||
worktree_id: u64,
|
||||
extensions: HashMap<String, usize>,
|
||||
extensions: HashMap<String, u32>,
|
||||
) -> Result<()> {
|
||||
self.background.simulate_random_delay().await;
|
||||
if !self.projects.lock().contains_key(&project_id) {
|
||||
|
|
|
@ -164,6 +164,7 @@ impl Server {
|
|||
.add_message_handler(Server::update_project)
|
||||
.add_message_handler(Server::register_project_activity)
|
||||
.add_request_handler(Server::update_worktree)
|
||||
.add_message_handler(Server::update_worktree_extensions)
|
||||
.add_message_handler(Server::start_language_server)
|
||||
.add_message_handler(Server::update_language_server)
|
||||
.add_message_handler(Server::update_diagnostic_summary)
|
||||
|
@ -996,9 +997,9 @@ impl Server {
|
|||
) -> Result<()> {
|
||||
let project_id = ProjectId::from_proto(request.payload.project_id);
|
||||
let worktree_id = request.payload.worktree_id;
|
||||
let (connection_ids, metadata_changed, extension_counts) = {
|
||||
let (connection_ids, metadata_changed) = {
|
||||
let mut store = self.store_mut().await;
|
||||
let (connection_ids, metadata_changed, extension_counts) = store.update_worktree(
|
||||
let (connection_ids, metadata_changed) = store.update_worktree(
|
||||
request.sender_id,
|
||||
project_id,
|
||||
worktree_id,
|
||||
|
@ -1007,12 +1008,8 @@ impl Server {
|
|||
&request.payload.updated_entries,
|
||||
request.payload.scan_id,
|
||||
)?;
|
||||
(connection_ids, metadata_changed, extension_counts.clone())
|
||||
(connection_ids, metadata_changed)
|
||||
};
|
||||
self.app_state
|
||||
.db
|
||||
.update_worktree_extensions(project_id, worktree_id, extension_counts)
|
||||
.await?;
|
||||
|
||||
broadcast(request.sender_id, connection_ids, |connection_id| {
|
||||
self.peer
|
||||
|
@ -1029,6 +1026,25 @@ impl Server {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
async fn update_worktree_extensions(
|
||||
self: Arc<Server>,
|
||||
request: TypedEnvelope<proto::UpdateWorktreeExtensions>,
|
||||
) -> Result<()> {
|
||||
let project_id = ProjectId::from_proto(request.payload.project_id);
|
||||
let worktree_id = request.payload.worktree_id;
|
||||
let extensions = request
|
||||
.payload
|
||||
.extensions
|
||||
.into_iter()
|
||||
.zip(request.payload.counts)
|
||||
.collect();
|
||||
self.app_state
|
||||
.db
|
||||
.update_worktree_extensions(project_id, worktree_id, extensions)
|
||||
.await?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn update_diagnostic_summary(
|
||||
self: Arc<Server>,
|
||||
request: TypedEnvelope<proto::UpdateDiagnosticSummary>,
|
||||
|
|
|
@ -3,12 +3,7 @@ use anyhow::{anyhow, Result};
|
|||
use collections::{btree_map, hash_map::Entry, BTreeMap, BTreeSet, HashMap, HashSet};
|
||||
use rpc::{proto, ConnectionId, Receipt};
|
||||
use serde::Serialize;
|
||||
use std::{
|
||||
mem,
|
||||
path::{Path, PathBuf},
|
||||
str,
|
||||
time::Duration,
|
||||
};
|
||||
use std::{mem, path::PathBuf, str, time::Duration};
|
||||
use time::OffsetDateTime;
|
||||
use tracing::instrument;
|
||||
|
||||
|
@ -59,8 +54,6 @@ pub struct Worktree {
|
|||
#[serde(skip)]
|
||||
pub entries: BTreeMap<u64, proto::Entry>,
|
||||
#[serde(skip)]
|
||||
pub extension_counts: HashMap<String, usize>,
|
||||
#[serde(skip)]
|
||||
pub diagnostic_summaries: BTreeMap<PathBuf, proto::DiagnosticSummary>,
|
||||
pub scan_id: u64,
|
||||
}
|
||||
|
@ -401,7 +394,6 @@ impl Store {
|
|||
for worktree in project.worktrees.values_mut() {
|
||||
worktree.diagnostic_summaries.clear();
|
||||
worktree.entries.clear();
|
||||
worktree.extension_counts.clear();
|
||||
}
|
||||
|
||||
Ok(Some(UnsharedProject {
|
||||
|
@ -632,7 +624,6 @@ impl Store {
|
|||
for worktree in project.worktrees.values_mut() {
|
||||
worktree.diagnostic_summaries.clear();
|
||||
worktree.entries.clear();
|
||||
worktree.extension_counts.clear();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -655,7 +646,7 @@ impl Store {
|
|||
removed_entries: &[u64],
|
||||
updated_entries: &[proto::Entry],
|
||||
scan_id: u64,
|
||||
) -> Result<(Vec<ConnectionId>, bool, HashMap<String, usize>)> {
|
||||
) -> Result<(Vec<ConnectionId>, bool)> {
|
||||
let project = self.write_project(project_id, connection_id)?;
|
||||
if !project.online {
|
||||
return Err(anyhow!("project is not online"));
|
||||
|
@ -667,45 +658,15 @@ impl Store {
|
|||
worktree.root_name = worktree_root_name.to_string();
|
||||
|
||||
for entry_id in removed_entries {
|
||||
if let Some(entry) = worktree.entries.remove(&entry_id) {
|
||||
if !entry.is_ignored {
|
||||
if let Some(extension) = extension_for_entry(&entry) {
|
||||
if let Some(count) = worktree.extension_counts.get_mut(extension) {
|
||||
*count = count.saturating_sub(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
worktree.entries.remove(&entry_id);
|
||||
}
|
||||
|
||||
for entry in updated_entries {
|
||||
if let Some(old_entry) = worktree.entries.insert(entry.id, entry.clone()) {
|
||||
if !old_entry.is_ignored {
|
||||
if let Some(extension) = extension_for_entry(&old_entry) {
|
||||
if let Some(count) = worktree.extension_counts.get_mut(extension) {
|
||||
*count = count.saturating_sub(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if !entry.is_ignored {
|
||||
if let Some(extension) = extension_for_entry(&entry) {
|
||||
if let Some(count) = worktree.extension_counts.get_mut(extension) {
|
||||
*count += 1;
|
||||
} else {
|
||||
worktree.extension_counts.insert(extension.into(), 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
worktree.entries.insert(entry.id, entry.clone());
|
||||
}
|
||||
|
||||
worktree.scan_id = scan_id;
|
||||
Ok((
|
||||
connection_ids,
|
||||
metadata_changed,
|
||||
worktree.extension_counts.clone(),
|
||||
))
|
||||
Ok((connection_ids, metadata_changed))
|
||||
}
|
||||
|
||||
pub fn project_connection_ids(
|
||||
|
@ -894,11 +855,3 @@ impl Channel {
|
|||
self.connection_ids.iter().copied().collect()
|
||||
}
|
||||
}
|
||||
|
||||
fn extension_for_entry(entry: &proto::Entry) -> Option<&str> {
|
||||
str::from_utf8(&entry.path)
|
||||
.ok()
|
||||
.map(Path::new)
|
||||
.and_then(|p| p.extension())
|
||||
.and_then(|e| e.to_str())
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue