From e885e8123fbe0d57a0d8a4c8115ea43dde31b05d Mon Sep 17 00:00:00 2001 From: ck Date: Mon, 15 Feb 2010 17:16:53 +0100 Subject: Assistant: Rebuild search index at most once at start-up. Reviewed-by: kh1 --- .../tools/assistant/helpenginewrapper.cpp | 28 +++++++++++++++++++++- .../assistant/tools/assistant/helpenginewrapper.h | 6 +++++ tools/assistant/tools/assistant/mainwindow.cpp | 3 +-- 3 files changed, 34 insertions(+), 3 deletions(-) diff --git a/tools/assistant/tools/assistant/helpenginewrapper.cpp b/tools/assistant/tools/assistant/helpenginewrapper.cpp index 76211c5..a181c71 100644 --- a/tools/assistant/tools/assistant/helpenginewrapper.cpp +++ b/tools/assistant/tools/assistant/helpenginewrapper.cpp @@ -112,6 +112,7 @@ private: QFileSystemWatcher * const m_qchWatcher; typedef QPair > RecentSignal; QMap m_recentQchUpdates; + bool m_initialReindexingNeeded; }; const QString HelpEngineWrapper::TrUnfiltered = tr("Unfiltered"); @@ -141,6 +142,18 @@ HelpEngineWrapper::HelpEngineWrapper(const QString &collectionFile) : d(new HelpEngineWrapperPrivate(collectionFile)) { TRACE_OBJ + + /* + * Otherwise we will waste time if several new docs are found, + * because we will start to index them, only to be interupted + * by the next request. Also, there is a nasty SQLITE bug that will + * cause the application to hang for minutes in that case. + * This call is reverted by initalDocSetupDone(), which must be + * called after the new docs have been installed. + */ + disconnect(d->m_helpEngine, SIGNAL(setupFinished()), + searchEngine(), SLOT(indexDocumentation())); + connect(d, SIGNAL(documentationRemoved(QString)), this, SIGNAL(documentationRemoved(QString))); connect(d, SIGNAL(documentationUpdated(QString)), @@ -157,6 +170,15 @@ HelpEngineWrapper::~HelpEngineWrapper() delete d; } +void HelpEngineWrapper::initialDocSetupDone() +{ + TRACE_OBJ + connect(d->m_helpEngine, SIGNAL(setupFinished()), + searchEngine(), SLOT(indexDocumentation())); + if (d->m_initialReindexingNeeded) + setupData(); +} + QHelpSearchEngine *HelpEngineWrapper::searchEngine() const { TRACE_OBJ @@ -207,6 +229,7 @@ bool HelpEngineWrapper::registerDocumentation(const QString &docFile) return false; d->m_qchWatcher->addPath(docFile); d->checkDocFilesWatched(); + d->m_initialReindexingNeeded = true; return true; } @@ -219,6 +242,7 @@ bool HelpEngineWrapper::unregisterDocumentation(const QString &namespaceName) return false; d->m_qchWatcher->removePath(file); d->checkDocFilesWatched(); + d->m_initialReindexingNeeded = true; return true; } @@ -698,7 +722,8 @@ void TimeoutForwarder::forward() HelpEngineWrapperPrivate::HelpEngineWrapperPrivate(const QString &collectionFile) : m_helpEngine(new QHelpEngine(collectionFile, this)), - m_qchWatcher(new QFileSystemWatcher(this)) + m_qchWatcher(new QFileSystemWatcher(this)), + m_initialReindexingNeeded(false) { TRACE_OBJ if (!m_helpEngine->customFilters().contains(Unfiltered)) @@ -797,6 +822,7 @@ void HelpEngineWrapperPrivate::qchFileChanged(const QString &fileName, } else { emit documentationUpdated(ns); } + m_initialReindexingNeeded = true; m_helpEngine->setupData(); } m_recentQchUpdates.erase(it); diff --git a/tools/assistant/tools/assistant/helpenginewrapper.h b/tools/assistant/tools/assistant/helpenginewrapper.h index a30fab8..8d95273 100644 --- a/tools/assistant/tools/assistant/helpenginewrapper.h +++ b/tools/assistant/tools/assistant/helpenginewrapper.h @@ -101,6 +101,12 @@ public: const QStringList filterAttributes(const QString &filterName) const; QString error() const; + /* + * To be called after assistant has finished looking for new documentation. + * This will mainly cause the search index to be updated, if necessary. + */ + void initialDocSetupDone(); + const QStringList qtDocInfo(const QString &component) const; void setQtDocInfo(const QString &component, const QStringList &doc); diff --git a/tools/assistant/tools/assistant/mainwindow.cpp b/tools/assistant/tools/assistant/mainwindow.cpp index 4115d39..8096218 100644 --- a/tools/assistant/tools/assistant/mainwindow.cpp +++ b/tools/assistant/tools/assistant/mainwindow.cpp @@ -354,8 +354,6 @@ void MainWindow::lookForNewQtDocumentation() void MainWindow::qtDocumentationInstalled(bool newDocsInstalled) { TRACE_OBJ - if (newDocsInstalled) - HelpEngineWrapper::instance().setupData(); statusBar()->clearMessage(); checkInitState(); } @@ -383,6 +381,7 @@ void MainWindow::checkInitState() } emit initDone(); } + HelpEngineWrapper::instance().initialDocSetupDone(); } void MainWindow::insertLastPages() -- cgit v0.12