Debounce and limit searches.

This commit is contained in:
Brübach, Lukas 2025-11-27 11:10:18 +01:00
parent d98bca8be8
commit fb557d2b14
2 changed files with 14 additions and 0 deletions

View file

@ -39,6 +39,12 @@ TabArchidekt::TabArchidekt(TabSupervisor *_tabSupervisor) : Tab(_tabSupervisor)
networkManager->setRedirectPolicy(QNetworkRequest::ManualRedirectPolicy);
connect(networkManager, SIGNAL(finished(QNetworkReply *)), this, SLOT(processApiJson(QNetworkReply *)));
searchDebounceTimer = new QTimer(this);
searchDebounceTimer->setSingleShot(true); // We only want it to fire once after inactivity
searchDebounceTimer->setInterval(300); // 300ms debounce
connect(searchDebounceTimer, &QTimer::timeout, this, [this]() { doSearchImmediate(); });
container = new QWidget(this);
mainLayout = new QVBoxLayout(container);
mainLayout->setContentsMargins(0, 0, 0, 0);
@ -417,6 +423,11 @@ QString TabArchidekt::buildSearchUrl()
}
void TabArchidekt::doSearch()
{
searchDebounceTimer->start();
}
void TabArchidekt::doSearchImmediate()
{
QString url = buildSearchUrl();
QNetworkRequest req{QUrl(url)};

View file

@ -73,6 +73,7 @@ public:
* Updates the current page display with results asynchronously.
*/
void doSearch();
void doSearchImmediate();
/**
* @brief Retrieve the tab display text
@ -149,6 +150,8 @@ public slots:
void getTopDecks();
private:
QTimer* searchDebounceTimer; ///< Timer to debounce search requests by spin-boxes etc.
// ---------------------------------------------------------------------
// Layout Containers
// ---------------------------------------------------------------------