From d745c2e616e953aad94eb1e899438bfab0b2baa2 Mon Sep 17 00:00:00 2001 From: Ulf Hermann Date: Thu, 15 Feb 2018 13:24:36 +0100 Subject: Assistant: Don't query the database for unneeded data If we only need registered documentations of a specific namespace we can restrict the SQL query accordingly, so that we don't have to iterate through all the results afterwards. Change-Id: I124cf16ed95e1010b8a05d8cb723c2a1f03120d4 Reviewed-by: Jarek Kobus --- src/assistant/help/qhelpcollectionhandler.cpp | 15 ++++++++++++--- src/assistant/help/qhelpcollectionhandler_p.h | 2 +- src/assistant/help/qhelpenginecore.cpp | 2 +- 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/src/assistant/help/qhelpcollectionhandler.cpp b/src/assistant/help/qhelpcollectionhandler.cpp index 163eefed1..5935295e6 100644 --- a/src/assistant/help/qhelpcollectionhandler.cpp +++ b/src/assistant/help/qhelpcollectionhandler.cpp @@ -355,12 +355,21 @@ bool QHelpCollectionHandler::addCustomFilter(const QString &filterName, return true; } -QHelpCollectionHandler::DocInfoList QHelpCollectionHandler::registeredDocumentations() const +QHelpCollectionHandler::DocInfoList QHelpCollectionHandler::registeredDocumentations( + const QString &namespaceName) const { DocInfoList list; if (m_dbOpened) { - m_query.exec(QLatin1String("SELECT a.Name, a.FilePath, b.Name " - "FROM NamespaceTable a, FolderTable b WHERE a.Id=b.NamespaceId")); + static const QLatin1String baseQuery("SELECT a.Name, a.FilePath, b.Name " + "FROM NamespaceTable a, FolderTable b " + "WHERE a.Id=b.NamespaceId"); + if (namespaceName.isEmpty()) { + m_query.prepare(baseQuery); + } else { + m_query.prepare(baseQuery + QLatin1String(" AND a.Name=? LIMIT 1")); + m_query.bindValue(0, namespaceName); + } + m_query.exec(); while (m_query.next()) { DocInfo info; diff --git a/src/assistant/help/qhelpcollectionhandler_p.h b/src/assistant/help/qhelpcollectionhandler_p.h index b2b249715..2b1b57718 100644 --- a/src/assistant/help/qhelpcollectionhandler_p.h +++ b/src/assistant/help/qhelpcollectionhandler_p.h @@ -88,7 +88,7 @@ public: bool addCustomFilter(const QString &filterName, const QStringList &attributes); - DocInfoList registeredDocumentations() const; + DocInfoList registeredDocumentations(const QString &namespaceName = QString()) const; bool registerDocumentation(const QString &fileName); bool unregisterDocumentation(const QString &namespaceName); diff --git a/src/assistant/help/qhelpenginecore.cpp b/src/assistant/help/qhelpenginecore.cpp index b3396f2fe..e351c07d1 100644 --- a/src/assistant/help/qhelpenginecore.cpp +++ b/src/assistant/help/qhelpenginecore.cpp @@ -351,7 +351,7 @@ QString QHelpEngineCore::documentationFileName(const QString &namespaceName) { if (d->setup()) { const QHelpCollectionHandler::DocInfoList &docList = - d->collectionHandler->registeredDocumentations(); + d->collectionHandler->registeredDocumentations(namespaceName); for (const QHelpCollectionHandler::DocInfo &info : docList) { if (info.namespaceName == namespaceName) { if (QDir::isAbsolutePath(info.fileName)) -- cgit v1.2.1