Skip to content
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

watcher refactor #3471

Merged
merged 17 commits into from
Apr 15, 2024
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
remove rate-limit as it never kicks in, and also, we'd want the compu…
…tation for correctness
  • Loading branch information
Byron committed Apr 15, 2024
commit 56642830f02fa4b57ff5ec8e028d27cf02edb727
28 changes: 0 additions & 28 deletions crates/gitbutler-tauri/src/watcher/handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ mod push_project_to_gitbutler;

use std::path::{Path, PathBuf};
use std::sync::Arc;
use std::time::Duration;
use std::{path, time};

use anyhow::{bail, Context, Result};
Expand All @@ -15,9 +14,6 @@ use gitbutler_core::{
assets, deltas, gb_repository, git, project_repository, projects, reader, sessions, users,
virtual_branches,
};
use governor::clock::QuantaClock;
use governor::state::{InMemoryState, NotKeyed};
use governor::{Quota, RateLimiter};
use tauri::{AppHandle, Manager};
use tracing::instrument;

Expand All @@ -38,14 +34,9 @@ pub struct Handler {
projects: projects::Controller,
vbranch_controller: virtual_branches::Controller,
assets_proxy: assets::Proxy,
/// A rate-limiter for the vbranch calculation.
calc_vbranch_limit: Arc<RateLimiter<NotKeyed, InMemoryState, QuantaClock>>,
sessions_db: sessions::Database,
deltas_db: deltas::Database,

/// A rate-limiter for the `is-ignored` computation
recalc_all_limit: Arc<RateLimiter<NotKeyed, InMemoryState, QuantaClock>>,

/// A function to send events - decoupled from app-handle for testing purposes.
#[allow(clippy::type_complexity)]
send_event: Arc<dyn Fn(&crate::events::Event) -> Result<()> + Send + Sync + 'static>,
Expand Down Expand Up @@ -100,26 +91,15 @@ impl Handler {
deltas_db: deltas::Database,
send_event: impl Fn(&crate::events::Event) -> Result<()> + Send + Sync + 'static,
) -> Self {
let calc_vbranch_limit = {
let quota = Quota::with_period(Duration::from_millis(100)).expect("valid quota");
Arc::new(RateLimiter::direct(quota))
};
// There could be an application (e.g an IDE) which is constantly writing, so the threshold cant be too high
let recalc_all_limit = {
let quota = Quota::with_period(Duration::from_millis(5)).expect("valid quota");
Arc::new(RateLimiter::direct(quota))
};
Handler {
local_data_dir,
analytics,
users,
projects,
vbranch_controller,
assets_proxy,
calc_vbranch_limit,
sessions_db,
deltas_db,
recalc_all_limit,
send_event: Arc::new(send_event),
}
}
Expand Down Expand Up @@ -226,10 +206,6 @@ impl Handler {

#[instrument(skip(self, project_id))]
async fn calculate_virtual_branches(&self, project_id: ProjectId) -> Result<()> {
if self.calc_vbranch_limit.check().is_err() {
tracing::warn!("rate limited");
return Ok(());
}
match self
.vbranch_controller
.list_virtual_branches(&project_id)
Expand Down Expand Up @@ -349,10 +325,6 @@ impl Handler {
paths: Vec<PathBuf>,
project_id: ProjectId,
) -> Result<()> {
if self.recalc_all_limit.check().is_err() {
tracing::warn!("rate limited");
return Ok(());
}
let calc_deltas = tokio::task::spawn_blocking({
let this = self.clone();
move || this.calculate_deltas(paths, project_id)
Expand Down