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

Fix over-calculation in when loading data in perspective-viewer #2323

Merged
merged 1 commit into from
Aug 7, 2023
Merged
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
62 changes: 37 additions & 25 deletions rust/perspective-viewer/src/rust/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ pub struct SessionData {
config: ViewConfig,
view_sub: Option<ViewSubscription>,
stats: Option<ViewStats>,
is_clean: bool,
}

impl Deref for Session {
Expand Down Expand Up @@ -107,6 +108,7 @@ impl Session {
/// # Arguments
/// - `keep_expressions` Whether to reset the `expressions` property.
pub fn reset(&self, reset_expressions: bool) {
self.borrow_mut().is_clean = false;
self.borrow_mut().view_sub = None;
self.borrow_mut().config.reset(reset_expressions);
}
Expand Down Expand Up @@ -306,8 +308,9 @@ impl Session {
/// Update the config, setting the `columns` property to the plugin defaults
/// if provided.
pub fn update_view_config(&self, config_update: ViewConfigUpdate) {
self.borrow_mut().view_sub = None;
if self.borrow_mut().config.apply_update(config_update) {
self.borrow_mut().view_sub = None;
self.0.borrow_mut().is_clean = false;
self.view_config_changed.emit_all(());
}
}
Expand Down Expand Up @@ -452,6 +455,12 @@ impl Session {
self.borrow_mut().config = config;
Ok(())
}

fn reset_clean(&self) -> bool {
let mut is_clean = true;
std::mem::swap(&mut is_clean, &mut self.0.borrow_mut().is_clean);
is_clean
}
}

/// A newtype wrapper which only provides `create_view()`
Expand All @@ -463,31 +472,34 @@ impl<'a> ValidSession<'a> {
/// the original `&Session`.
pub async fn create_view(&self) -> Result<&'a Session, ApiError> {
let js_config = self.0.borrow().config.as_jsvalue()?;
let table = self
.0
.borrow()
.table
.clone()
.ok_or("`restore()` called before `load()`")?;

let view = table.view(&js_config).await?;
let view_schema = view.schema().await?;
self.0.metadata_mut().update_view_schema(&view_schema)?;

let on_stats = Callback::from({
let this = self.0.clone();
move |stats| this.update_stats(stats)
});

let sub = {
let config = self.0.borrow().config.clone();
let on_update = self.0.table_updated.callback();
ViewSubscription::new(view, config, on_stats, on_update)
};
if !self.0.reset_clean() {
let table = self
.0
.borrow()
.table
.clone()
.ok_or("`restore()` called before `load()`")?;

let view = table.view(&js_config).await?;
let view_schema = view.schema().await?;
self.0.metadata_mut().update_view_schema(&view_schema)?;

let on_stats = Callback::from({
let this = self.0.clone();
move |stats| this.update_stats(stats)
});

let sub = {
let config = self.0.borrow().config.clone();
let on_update = self.0.table_updated.callback();
ViewSubscription::new(view, config, on_stats, on_update)
};

// self.0.borrow_mut().metadata.as_mut().unwrap().view_schema =
// Some(view_schema);
self.0.borrow_mut().view_sub = Some(sub);
}

// self.0.borrow_mut().metadata.as_mut().unwrap().view_schema =
// Some(view_schema);
self.0.borrow_mut().view_sub = Some(sub);
Ok(self.0)
}
}
Expand Down
Loading