Skip to content

Commit 4ae6661

Browse files
committed
Native: Move handling search operation to UI
* Move operation tracking for search to UI state to handle all operations in one side. * Improve UI handling for search state since more infos are available. * Best possible fixes to searches going out of sync in UI without changing search logic in rust core.
1 parent 80c2268 commit 4ae6661

File tree

10 files changed

+163
-70
lines changed

10 files changed

+163
-70
lines changed

application/apps/indexer/gui/application/src/session/command.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ use std::sync::mpsc::Sender;
44

55
use processor::{grabber::LineRange, search::filter::SearchFilter};
66
use stypes::GrabbedElement;
7+
use uuid::Uuid;
78

89
use crate::session::error::SessionError;
910

@@ -16,9 +17,14 @@ use crate::session::error::SessionError;
1617
#[derive(Debug)]
1718
pub enum SessionCommand {
1819
/// Apply the provided search filters.
19-
ApplySearchFilter(Vec<SearchFilter>),
20+
ApplySearchFilter {
21+
operation_id: Uuid,
22+
filters: Vec<SearchFilter>,
23+
},
2024
/// Cancel current search and clear results.
21-
DropSearch,
25+
/// If search operation is still processing then a search id will be provided
26+
/// to abort this operation.
27+
DropSearch { operation_id: Option<Uuid> },
2228
/// Request the nearest index in the search view for a given main-log index.
2329
GetNearestPosition(u64),
2430

application/apps/indexer/gui/application/src/session/service/mod.rs

Lines changed: 14 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,12 @@ use crate::{
1919
ui::{SessionInfo, chart::ChartBar},
2020
},
2121
};
22-
use operation_track::OperationTracker;
23-
24-
mod operation_track;
2522

2623
#[derive(Debug)]
2724
pub struct SessionService {
2825
cmd_rx: mpsc::Receiver<SessionCommand>,
2926
senders: ServiceSenders,
3027
session: Session,
31-
ops_tracker: OperationTracker,
3228
callback_rx: mpsc::UnboundedReceiver<CallbackEvent>,
3329
}
3430

@@ -58,7 +54,6 @@ impl SessionService {
5854
cmd_rx,
5955
senders,
6056
session,
61-
ops_tracker: OperationTracker::default(),
6257
callback_rx,
6358
};
6459

@@ -155,17 +150,14 @@ impl SessionService {
155150
);
156151
}
157152
}
158-
SessionCommand::ApplySearchFilter(search_filters) => {
159-
let op_id = Uuid::new_v4();
160-
debug_assert!(
161-
self.ops_tracker.filter_op.is_none(),
162-
"filter must be dropped before applying new one"
163-
);
164-
self.ops_tracker.filter_op = Some(op_id);
165-
self.session.apply_search_filters(op_id, search_filters)?;
153+
SessionCommand::ApplySearchFilter {
154+
operation_id,
155+
filters,
156+
} => {
157+
self.session.apply_search_filters(operation_id, filters)?;
166158
}
167-
SessionCommand::DropSearch => {
168-
if let Some(filter_op) = self.ops_tracker.filter_op.take() {
159+
SessionCommand::DropSearch { operation_id } => {
160+
if let Some(filter_op) = operation_id {
169161
self.session.abort(Uuid::new_v4(), filter_op)?;
170162
}
171163
self.session.drop_search().await?;
@@ -254,11 +246,6 @@ impl SessionService {
254246
SessionCommand::CloseSession => {
255247
// Session UI can be already dropped at this point, therefore
256248
// we don't need to send errors to UI in this case.
257-
for op_id in self.ops_tracker.get_all() {
258-
if let Err(err) = self.session.abort(Uuid::new_v4(), op_id) {
259-
log::error!("Abort operation failed. {err:?}");
260-
}
261-
}
262249

263250
if let Err(err) = self.session.stop(Uuid::new_v4()).await {
264251
log::error!("Stopping session failed. {err:?}");
@@ -283,21 +270,20 @@ impl SessionService {
283270
.send_session_msg(SessionMessage::LogsCount(logs_count))
284271
.await;
285272
}
286-
// TODO AAZ: Search callbacks seem to have duplications. Check
287-
// how they're used in master.
288-
//
289-
// CallbackEvent::SearchUpdated { found, stat } => {
290-
// }
273+
CallbackEvent::SearchUpdated { found, stat: _ } => {
274+
// TODO AAZ: For now I'm updating the total count of logs.
275+
// But this will be changed once we got to multiple filters.
276+
self.senders
277+
.send_session_msg(SessionMessage::SearchState { found_count: found })
278+
.await;
279+
}
291280
CallbackEvent::IndexedMapUpdated { len } => {
292281
self.senders
293282
.send_session_msg(SessionMessage::SearchState { found_count: len })
294283
.await;
295284
}
296285
CallbackEvent::SearchMapUpdated(filter_matches) => {
297286
if let Some(list) = filter_matches {
298-
// Long process ends when it deliver its initial results.
299-
self.ops_tracker.filter_op = None;
300-
301287
self.senders
302288
.send_session_msg(SessionMessage::SearchResults(list.0))
303289
.await;

application/apps/indexer/gui/application/src/session/ui/bottom_panel/chart/mod.rs

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
use std::{ops::RangeInclusive, time::Duration};
22

3-
use egui::{Color32, Direction, Label, Layout, Ui, Vec2, Widget};
3+
use egui::{Color32, Direction, Label, Layout, Spinner, Ui, Vec2, Widget};
44
use egui_plot::{Bar, BarChart, Legend, Plot};
55
use tokio::sync::mpsc::Sender;
66

77
use crate::{
88
common::action_throttle::ActionThrottle,
99
host::ui::UiActions,
10-
session::{command::SessionCommand, ui::shared::SessionShared},
10+
session::{command::SessionCommand, types::OperationPhase, ui::shared::SessionShared},
1111
};
1212

1313
pub use data::{ChartBar, ChartsData};
@@ -82,10 +82,18 @@ impl ChartUI {
8282
actions: &mut UiActions,
8383
ui: &mut Ui,
8484
) {
85-
if shared.search.is_search_active() {
86-
self.chart(shared, actions, ui);
87-
} else {
88-
Self::place_holder(ui);
85+
match shared.search.search_operation_phase() {
86+
Some(OperationPhase::Initializing) => {
87+
ui.centered_and_justified(|ui| {
88+
Spinner::new().size(20.0).ui(ui);
89+
});
90+
}
91+
Some(OperationPhase::Processing | OperationPhase::Done) => {
92+
self.chart(shared, actions, ui);
93+
}
94+
None => {
95+
Self::place_holder(ui);
96+
}
8997
}
9098
}
9199

@@ -177,7 +185,7 @@ impl ChartUI {
177185
plot_ui.set_auto_bounds([false, true]);
178186
}
179187

180-
if shared.search.total_count == 0 {
188+
if shared.search.total_count() == 0 {
181189
return PlotResponse::None;
182190
}
183191

@@ -203,7 +211,7 @@ impl ChartUI {
203211
return PlotResponse::RequestForRange(bounds_x);
204212
}
205213
}
206-
None if shared.search.total_count > 0 => {
214+
None if shared.search.total_count() > 0 => {
207215
// This is the first render frame after having search results.
208216

209217
//TODO AAZ: It would make sense to update this on logs_count changed.

application/apps/indexer/gui/application/src/session/ui/bottom_panel/search/mod.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ use crate::{
88
host::ui::UiActions,
99
session::{
1010
command::SessionCommand,
11+
types::OperationPhase,
1112
ui::{definitions::schema::LogSchema, shared::SessionShared},
1213
},
1314
};
@@ -40,7 +41,11 @@ impl SearchUI {
4041
) {
4142
self.bar.render_content(shared, actions, ui);
4243

43-
if shared.search.is_search_active() {
44+
if shared
45+
.search
46+
.search_operation_phase()
47+
.is_some_and(|ph| ph != OperationPhase::Initializing)
48+
{
4449
// We need to give a unique id for the direct parent of each table because
4550
// they will be used as identifiers for table state to avoid ID clashes between
4651
// tables from different tabs (different sessions).

application/apps/indexer/gui/application/src/session/ui/bottom_panel/search/search_bar.rs

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,12 @@ use egui::{
55
Ui, Widget, vec2,
66
};
77
use processor::search::filter::SearchFilter;
8+
use uuid::Uuid;
89

910
use crate::{
1011
common::phosphor::{self, icons},
1112
host::ui::UiActions,
12-
session::{command::SessionCommand, ui::shared::SessionShared},
13+
session::{command::SessionCommand, types::OperationPhase, ui::shared::SessionShared},
1314
};
1415

1516
#[derive(Debug, Clone)]
@@ -80,9 +81,13 @@ impl SearchBar {
8081
self.is_word,
8182
);
8283

83-
let cmd = SessionCommand::ApplySearchFilter(vec![filter.clone()]);
84+
let operation_id = Uuid::new_v4();
85+
let cmd = SessionCommand::ApplySearchFilter {
86+
operation_id,
87+
filters: vec![filter.clone()],
88+
};
8489
if actions.try_send_command(&self.cmd_tx, cmd) {
85-
shared.search.activate();
90+
shared.search.set_search_operation(operation_id);
8691
self.temp_filter = Some(filter);
8792
}
8893
}
@@ -214,15 +219,20 @@ impl SearchBar {
214219
}
215220

216221
ui.horizontal_centered(|ui| {
217-
let percentage = shared.search.total_count as f32 / logs_count as f32 * 100.;
222+
let percentage = shared.search.total_count() as f32 / logs_count as f32 * 100.;
218223

219224
let state_txt = format!(
220225
"{}/{} ({percentage:.2}%)",
221-
shared.search.total_count, logs_count,
226+
shared.search.total_count(),
227+
logs_count,
222228
);
223229
Label::new(state_txt).selectable(false).ui(ui);
224230

225-
if shared.search.current_matches_map().is_none() {
231+
if shared
232+
.search
233+
.search_operation_phase()
234+
.is_some_and(|ph| ph == OperationPhase::Initializing)
235+
{
226236
ui.spinner();
227237
}
228238
});
@@ -231,7 +241,8 @@ impl SearchBar {
231241
}
232242

233243
fn drop_search(&self, shared: &mut SessionShared, actions: &mut UiActions) {
234-
actions.try_send_command(&self.cmd_tx, SessionCommand::DropSearch);
244+
let operation_id = shared.search.processing_search_operation();
245+
actions.try_send_command(&self.cmd_tx, SessionCommand::DropSearch { operation_id });
235246
shared.drop_search();
236247
}
237248
}

application/apps/indexer/gui/application/src/session/ui/bottom_panel/search/search_table.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,14 +71,14 @@ impl SearchTable {
7171

7272
let mut table = egui_table::Table::new()
7373
.id_salt(id_salt)
74-
.num_rows(shared.search.total_count)
74+
.num_rows(shared.search.total_count())
7575
.headers(Vec::new())
7676
.columns(self.columns.as_ref())
7777
.auto_size_mode(AutoSizeMode::Never)
7878
.num_sticky_cols(1);
7979

8080
if let Some(row_nr) = self.scroll_nearest_pos.take().map(|pos| pos.index)
81-
&& row_nr < shared.search.total_count
81+
&& row_nr < shared.search.total_count()
8282
{
8383
const OFFSET: u64 = 2;
8484
table = table.scroll_to_rows(row_nr.saturating_sub(OFFSET)..=row_nr + OFFSET, None);
@@ -180,7 +180,7 @@ impl TableDelegate for LogsDelegate<'_> {
180180
// Request new data.
181181
self.table.last_visible_rows = Some(info.visible_rows.to_owned());
182182

183-
if self.shared.search.total_count == 0 {
183+
if self.shared.search.total_count() == 0 {
184184
return;
185185
}
186186

application/apps/indexer/gui/application/src/session/ui/mod.rs

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ impl Session {
168168
self.shared.logs.selected_log = selected;
169169
}
170170
SessionMessage::SearchState { found_count } => {
171-
self.shared.search.total_count = found_count;
171+
self.shared.search.set_total_count(found_count);
172172
self.bottom_panel
173173
.chart
174174
.on_search_count_changes(&self.shared);
@@ -199,7 +199,20 @@ impl Session {
199199
operation_id,
200200
phase,
201201
} => {
202-
if self.shared.observe.update(operation_id, phase).consumed() {
202+
if self
203+
.shared
204+
.observe
205+
.update_operation(operation_id, phase)
206+
.consumed()
207+
{
208+
return;
209+
}
210+
if self
211+
.shared
212+
.search
213+
.update_operation(operation_id, phase)
214+
.consumed()
215+
{
203216
return;
204217
}
205218
// Potential components which keep track for operations can go here.

application/apps/indexer/gui/application/src/session/ui/shared/observe.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,11 @@ impl ObserveState {
1717
}
1818
}
1919

20-
pub fn update(&mut self, operation_id: Uuid, phase: OperationPhase) -> UpdateOperationOutcome {
20+
pub fn update_operation(
21+
&mut self,
22+
operation_id: Uuid,
23+
phase: OperationPhase,
24+
) -> UpdateOperationOutcome {
2125
if let Some(observe) = self.operations.iter_mut().find(|o| o.id == operation_id) {
2226
observe.set_phase(phase);
2327
UpdateOperationOutcome::Consumed

0 commit comments

Comments
 (0)