From df74bc4c98036f6b0bddf1c9baf772274e33606a Mon Sep 17 00:00:00 2001 From: littleblack111 Date: Sun, 26 Jul 2026 20:11:59 +0800 Subject: perf(SmartCalc): cahce query in event of multiple component calling query at once with the same query cleanup: no longer needed qml and unused import --- qml_plugin/src/launcher/calc.rs | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) (limited to 'qml_plugin') diff --git a/qml_plugin/src/launcher/calc.rs b/qml_plugin/src/launcher/calc.rs index 196484e..7b1b066 100644 --- a/qml_plugin/src/launcher/calc.rs +++ b/qml_plugin/src/launcher/calc.rs @@ -1,6 +1,6 @@ -use cxx_qt::{QObject, Threading}; -use cxx_qt_lib::{QDateTime, QString, QVariant}; -use std::{pin::Pin, sync::mpsc, time::Duration}; +use cxx_qt::Threading; +use cxx_qt_lib::{QString, QVariant}; +use std::pin::Pin; use crate::RUNTIME; @@ -24,6 +24,10 @@ mod qobject { ResultType, result_type )] + #[qproperty( + QVariant, + cached_query + )] type SmartCalc = super::SmartCalcRs; #[qinvokable] @@ -70,10 +74,17 @@ impl From<&smart_calculator::types::ResultType> for qobject::ResultType { pub struct SmartCalcRs { result: QVariant, result_type: qobject::ResultType, + + cached_query: QVariant, } impl qobject::SmartCalc { - fn query(self: Pin<&mut Self>, input: QString) { + fn query(mut self: Pin<&mut Self>, input: QString) { + if self.cached_query == (&input).into() { + return; + } + self.as_mut() + .set_cached_query((&input.clone()).into()); let qt_thread = self.qt_thread(); RUNTIME.spawn( async move { @@ -118,5 +129,7 @@ impl qobject::SmartCalc { .set_result(QVariant::default()); self.as_mut() .set_result_type(qobject::ResultType::Unset); + self.as_mut() + .set_cached_query(QVariant::default()); } } -- cgit v1.2.3