mirror of
https://github.com/zed-industries/zed.git
synced 2024-09-19 02:17:35 +03:00
Remove immediate flush mode
Allow flush method to be called publicly. This is a better, simpler solution, that allows for better control over flushing.
This commit is contained in:
parent
520c433af5
commit
5344296c9a
@ -193,7 +193,8 @@ impl Telemetry {
|
||||
// TestAppContext ends up calling this function on shutdown and it panics when trying to find the TelemetrySettings
|
||||
#[cfg(not(any(test, feature = "test-support")))]
|
||||
fn shutdown_telemetry(self: &Arc<Self>) -> impl Future<Output = ()> {
|
||||
self.report_app_event("close", true);
|
||||
self.report_app_event("close");
|
||||
self.flush_clickhouse_events();
|
||||
Task::ready(())
|
||||
}
|
||||
|
||||
@ -283,7 +284,7 @@ impl Telemetry {
|
||||
milliseconds_since_first_event: self.milliseconds_since_first_event(),
|
||||
};
|
||||
|
||||
self.report_clickhouse_event(event, false)
|
||||
self.report_clickhouse_event(event)
|
||||
}
|
||||
|
||||
pub fn report_copilot_event(
|
||||
@ -299,7 +300,7 @@ impl Telemetry {
|
||||
milliseconds_since_first_event: self.milliseconds_since_first_event(),
|
||||
};
|
||||
|
||||
self.report_clickhouse_event(event, false)
|
||||
self.report_clickhouse_event(event)
|
||||
}
|
||||
|
||||
pub fn report_assistant_event(
|
||||
@ -315,7 +316,7 @@ impl Telemetry {
|
||||
milliseconds_since_first_event: self.milliseconds_since_first_event(),
|
||||
};
|
||||
|
||||
self.report_clickhouse_event(event, false)
|
||||
self.report_clickhouse_event(event)
|
||||
}
|
||||
|
||||
pub fn report_call_event(
|
||||
@ -331,7 +332,7 @@ impl Telemetry {
|
||||
milliseconds_since_first_event: self.milliseconds_since_first_event(),
|
||||
};
|
||||
|
||||
self.report_clickhouse_event(event, false)
|
||||
self.report_clickhouse_event(event)
|
||||
}
|
||||
|
||||
pub fn report_cpu_event(self: &Arc<Self>, usage_as_percentage: f32, core_count: u32) {
|
||||
@ -341,7 +342,7 @@ impl Telemetry {
|
||||
milliseconds_since_first_event: self.milliseconds_since_first_event(),
|
||||
};
|
||||
|
||||
self.report_clickhouse_event(event, false)
|
||||
self.report_clickhouse_event(event)
|
||||
}
|
||||
|
||||
pub fn report_memory_event(
|
||||
@ -355,16 +356,16 @@ impl Telemetry {
|
||||
milliseconds_since_first_event: self.milliseconds_since_first_event(),
|
||||
};
|
||||
|
||||
self.report_clickhouse_event(event, false)
|
||||
self.report_clickhouse_event(event)
|
||||
}
|
||||
|
||||
pub fn report_app_event(self: &Arc<Self>, operation: &'static str, immediate_flush: bool) {
|
||||
pub fn report_app_event(self: &Arc<Self>, operation: &'static str) {
|
||||
let event = ClickhouseEvent::App {
|
||||
operation,
|
||||
milliseconds_since_first_event: self.milliseconds_since_first_event(),
|
||||
};
|
||||
|
||||
self.report_clickhouse_event(event, immediate_flush)
|
||||
self.report_clickhouse_event(event)
|
||||
}
|
||||
|
||||
pub fn report_setting_event(self: &Arc<Self>, setting: &'static str, value: String) {
|
||||
@ -374,7 +375,7 @@ impl Telemetry {
|
||||
milliseconds_since_first_event: self.milliseconds_since_first_event(),
|
||||
};
|
||||
|
||||
self.report_clickhouse_event(event, false)
|
||||
self.report_clickhouse_event(event)
|
||||
}
|
||||
|
||||
fn milliseconds_since_first_event(&self) -> i64 {
|
||||
@ -391,7 +392,7 @@ impl Telemetry {
|
||||
}
|
||||
}
|
||||
|
||||
fn report_clickhouse_event(self: &Arc<Self>, event: ClickhouseEvent, immediate_flush: bool) {
|
||||
fn report_clickhouse_event(self: &Arc<Self>, event: ClickhouseEvent) {
|
||||
let mut state = self.state.lock();
|
||||
|
||||
if !state.settings.metrics {
|
||||
@ -404,7 +405,7 @@ impl Telemetry {
|
||||
.push(ClickhouseEventWrapper { signed_in, event });
|
||||
|
||||
if state.installation_id.is_some() {
|
||||
if immediate_flush || state.clickhouse_events_queue.len() >= MAX_QUEUE_LEN {
|
||||
if state.clickhouse_events_queue.len() >= MAX_QUEUE_LEN {
|
||||
drop(state);
|
||||
self.flush_clickhouse_events();
|
||||
} else {
|
||||
@ -430,7 +431,7 @@ impl Telemetry {
|
||||
self.state.lock().is_staff
|
||||
}
|
||||
|
||||
fn flush_clickhouse_events(self: &Arc<Self>) {
|
||||
pub fn flush_clickhouse_events(self: &Arc<Self>) {
|
||||
let mut state = self.state.lock();
|
||||
state.first_event_datetime = None;
|
||||
let mut events = mem::take(&mut state.clickhouse_events_queue);
|
||||
|
@ -86,7 +86,7 @@ impl Render for WelcomePage {
|
||||
.full_width()
|
||||
.on_click(cx.listener(|this, _, cx| {
|
||||
this.telemetry
|
||||
.report_app_event("welcome page button: theme", false);
|
||||
.report_app_event("welcome page button: theme");
|
||||
this.workspace
|
||||
.update(cx, |workspace, cx| {
|
||||
theme_selector::toggle(
|
||||
@ -103,7 +103,7 @@ impl Render for WelcomePage {
|
||||
.full_width()
|
||||
.on_click(cx.listener(|this, _, cx| {
|
||||
this.telemetry
|
||||
.report_app_event("welcome page button: keymap", false);
|
||||
.report_app_event("welcome page button: keymap");
|
||||
this.workspace
|
||||
.update(cx, |workspace, cx| {
|
||||
base_keymap_picker::toggle(
|
||||
@ -119,10 +119,8 @@ impl Render for WelcomePage {
|
||||
Button::new("install-cli", "Install the CLI")
|
||||
.full_width()
|
||||
.on_click(cx.listener(|this, _, cx| {
|
||||
this.telemetry.report_app_event(
|
||||
"welcome page button: install cli",
|
||||
false,
|
||||
);
|
||||
this.telemetry
|
||||
.report_app_event("welcome page button: install cli");
|
||||
cx.app_mut()
|
||||
.spawn(
|
||||
|cx| async move { install_cli::install_cli(&cx).await },
|
||||
@ -153,10 +151,8 @@ impl Render for WelcomePage {
|
||||
)
|
||||
.on_click(cx.listener(
|
||||
move |this, selection, cx| {
|
||||
this.telemetry.report_app_event(
|
||||
"welcome page button: vim",
|
||||
false,
|
||||
);
|
||||
this.telemetry
|
||||
.report_app_event("welcome page button: vim");
|
||||
this.update_settings::<VimModeSetting>(
|
||||
selection,
|
||||
cx,
|
||||
@ -183,7 +179,6 @@ impl Render for WelcomePage {
|
||||
move |this, selection, cx| {
|
||||
this.telemetry.report_app_event(
|
||||
"welcome page button: user telemetry",
|
||||
false,
|
||||
);
|
||||
this.update_settings::<TelemetrySettings>(
|
||||
selection,
|
||||
@ -222,7 +217,6 @@ impl Render for WelcomePage {
|
||||
move |this, selection, cx| {
|
||||
this.telemetry.report_app_event(
|
||||
"welcome page button: crash diagnostics",
|
||||
false,
|
||||
);
|
||||
this.update_settings::<TelemetrySettings>(
|
||||
selection,
|
||||
@ -254,7 +248,7 @@ impl WelcomePage {
|
||||
pub fn new(workspace: &Workspace, cx: &mut ViewContext<Workspace>) -> View<Self> {
|
||||
let this = cx.new_view(|cx| {
|
||||
cx.on_release(|this: &mut Self, _, _| {
|
||||
this.telemetry.report_app_event("close welcome page", false);
|
||||
this.telemetry.report_app_event("close welcome page");
|
||||
})
|
||||
.detach();
|
||||
|
||||
|
@ -1258,9 +1258,7 @@ impl Workspace {
|
||||
}
|
||||
|
||||
pub fn open(&mut self, _: &Open, cx: &mut ViewContext<Self>) {
|
||||
self.client()
|
||||
.telemetry()
|
||||
.report_app_event("open project", false);
|
||||
self.client().telemetry().report_app_event("open project");
|
||||
let paths = cx.prompt_for_paths(PathPromptOptions {
|
||||
files: true,
|
||||
directories: true,
|
||||
|
@ -175,13 +175,11 @@ fn main() {
|
||||
telemetry.start(installation_id, session_id, cx);
|
||||
telemetry.report_setting_event("theme", cx.theme().name.to_string());
|
||||
telemetry.report_setting_event("keymap", BaseKeymap::get_global(cx).to_string());
|
||||
telemetry.report_app_event(
|
||||
match existing_installation_id_found {
|
||||
Some(false) => "first open",
|
||||
_ => "open",
|
||||
},
|
||||
true,
|
||||
);
|
||||
telemetry.report_app_event(match existing_installation_id_found {
|
||||
Some(false) => "first open",
|
||||
_ => "open",
|
||||
});
|
||||
telemetry.flush_clickhouse_events();
|
||||
|
||||
let app_state = Arc::new(AppState {
|
||||
languages: languages.clone(),
|
||||
|
Loading…
Reference in New Issue
Block a user