fix: filter rows sometime not working (#6272)

This commit is contained in:
Nathan.fooo 2024-09-10 23:41:06 +08:00 committed by GitHub
parent 2ef896fb4a
commit 7d2719dd71
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -331,23 +331,21 @@ impl FilterController {
if let Some((_, row_detail)) = self.delegate.get_row(&self.view_id, &row_id).await { if let Some((_, row_detail)) = self.delegate.get_row(&self.view_id, &row_id).await {
let field_by_field_id = self.get_field_map().await; let field_by_field_id = self.get_field_map().await;
let mut notification = FilterResultNotification::new(self.view_id.clone()); let mut notification = FilterResultNotification::new(self.view_id.clone());
if let Some(is_visible) = filter_row( if filter_row(
&row_detail.row, &row_detail.row,
&self.result_by_row_id, &self.result_by_row_id,
&field_by_field_id, &field_by_field_id,
&self.cell_cache, &self.cell_cache,
&filters, &filters,
) { ) {
if is_visible { if let Some((index, _row)) = self.delegate.get_row(&self.view_id, &row_id).await {
if let Some((index, _row)) = self.delegate.get_row(&self.view_id, &row_id).await { notification.visible_rows.push(
notification.visible_rows.push( InsertedRowPB::new(RowMetaPB::from(row_detail.as_ref().clone()))
InsertedRowPB::new(RowMetaPB::from(row_detail.as_ref().clone())) .with_index(index as i32),
.with_index(index as i32), )
)
}
} else {
notification.invisible_rows.push(row_id);
} }
} else {
notification.invisible_rows.push(row_id);
} }
let _ = self let _ = self
@ -363,23 +361,23 @@ impl FilterController {
let mut visible_rows = vec![]; let mut visible_rows = vec![];
let mut invisible_rows = vec![]; let mut invisible_rows = vec![];
for (index, row) in rows.iter_mut().enumerate() { for (index, row) in rows.iter_mut().enumerate() {
if let Some(is_visible) = filter_row( if filter_row(
row, row,
&self.result_by_row_id, &self.result_by_row_id,
&field_by_field_id, &field_by_field_id,
&self.cell_cache, &self.cell_cache,
&filters, &filters,
) { ) {
if is_visible { let row_meta = RowMetaPB::from(row.as_ref());
let row_meta = RowMetaPB::from(row.as_ref()); visible_rows.push(InsertedRowPB::new(row_meta).with_index(index as i32))
visible_rows.push(InsertedRowPB::new(row_meta).with_index(index as i32)) } else {
} else { invisible_rows.push(row.id.clone());
invisible_rows.push(row.id.clone());
}
} }
} }
let len = rows.len();
rows.retain(|row| !invisible_rows.iter().any(|id| id == &row.id)); rows.retain(|row| !invisible_rows.iter().any(|id| id == &row.id));
trace!("[Database]: filter out {} invisible rows", len - rows.len());
let notification = FilterResultNotification { let notification = FilterResultNotification {
view_id: self.view_id.clone(), view_id: self.view_id.clone(),
invisible_rows, invisible_rows,
@ -458,11 +456,9 @@ fn filter_row(
field_by_field_id: &HashMap<String, Field>, field_by_field_id: &HashMap<String, Field>,
cell_data_cache: &CellCache, cell_data_cache: &CellCache,
filters: &Vec<Filter>, filters: &Vec<Filter>,
) -> Option<bool> { ) -> bool {
// Create a filter result cache if it doesn't exist // Create a filter result cache if it doesn't exist
let mut filter_result = result_by_row_id.entry(row.id.clone()).or_insert(true); let mut filter_result = result_by_row_id.entry(row.id.clone()).or_insert(true);
let old_is_visible = *filter_result;
let mut new_is_visible = true; let mut new_is_visible = true;
for filter in filters { for filter in filters {
@ -477,12 +473,7 @@ fn filter_row(
} }
*filter_result = new_is_visible; *filter_result = new_is_visible;
new_is_visible
if old_is_visible != new_is_visible {
Some(new_is_visible)
} else {
None
}
} }
/// Recursively applies a `Filter` to a `Row`'s cells. /// Recursively applies a `Filter` to a `Row`'s cells.