From 9adb8e6643793c85926ac2a22a17ebcc8d01c9b0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Fauconnier?= Date: Mon, 13 Jan 2020 17:26:48 +0100 Subject: [PATCH] Due to perfomance issues at openboard start, in a network-attached storage context, I had to find some (dirty) optimizations in order to counter-balance the huge response time of the directory scans performed when creating the documents tree (very huge in slowest machines (HDD, low CPU, with a thousand documents)). The simplest solution (I found) was to let the opening of metadatas fail, and to prevent any scanning. This implied to introduce the page-count as a metadata. As this issue is not encountered with a standard use of OpenBoard (with local documents), no update operation (of every document) should be necessary out of the described context --- src/adaptors/UBMetadataDcSubsetAdaptor.cpp | 7 +++ src/core/UBPersistenceManager.cpp | 52 ++++++++++++---------- src/core/UBSettings.cpp | 1 + src/core/UBSettings.h | 1 + src/document/UBDocumentProxy.cpp | 12 ++++- src/document/UBDocumentProxy.h | 1 + 6 files changed, 49 insertions(+), 25 deletions(-) diff --git a/src/adaptors/UBMetadataDcSubsetAdaptor.cpp b/src/adaptors/UBMetadataDcSubsetAdaptor.cpp index 54ce6d51..9cbe55eb 100644 --- a/src/adaptors/UBMetadataDcSubsetAdaptor.cpp +++ b/src/adaptors/UBMetadataDcSubsetAdaptor.cpp @@ -125,6 +125,8 @@ void UBMetadataDcSubsetAdaptor::persist(UBDocumentProxy* proxy) // introduced in UB 4.4 xmlWriter.writeTextElement(UBSettings::uniboardDocumentNamespaceUri, "updated-at", UBStringUtils::toUtcIsoDateTime(QDateTime::currentDateTimeUtc())); + xmlWriter.writeTextElement(UBSettings::uniboardDocumentNamespaceUri, "page-count", QString::number(proxy->pageCount())); + xmlWriter.writeEndElement(); //dc:Description xmlWriter.writeEndElement(); //RDF @@ -224,6 +226,11 @@ QMap UBMetadataDcSubsetAdaptor::load(QString pPath) metadata.insert(UBSettings::documentUpdatedAt, xml.readElementText()); updatedAtFound = true; } + else if (xml.name() == "page-count" + && xml.namespaceUri() == UBSettings::uniboardDocumentNamespaceUri) + { + metadata.insert(UBSettings::documentPageCount, xml.readElementText()); + } metadata.insert(UBSettings::documentVersion, docVersion); } diff --git a/src/core/UBPersistenceManager.cpp b/src/core/UBPersistenceManager.cpp index df371c6d..73dacd31 100644 --- a/src/core/UBPersistenceManager.cpp +++ b/src/core/UBPersistenceManager.cpp @@ -164,36 +164,40 @@ void UBPersistenceManager::createDocumentProxiesStructure(const QFileInfoList &c { QString fullPath = path.absoluteFilePath(); - QDir dir(fullPath); + QMap metadatas = UBMetadataDcSubsetAdaptor::load(fullPath); - if (dir.entryList(QDir::Files | QDir::NoDotAndDotDot).size() > 0) - { - QMap metadatas = UBMetadataDcSubsetAdaptor::load(fullPath); - QString docGroupName = metadatas.value(UBSettings::documentGroupName, QString()).toString(); - QString docName = metadatas.value(UBSettings::documentName, QString()).toString(); - - if (docName.isEmpty()) { - qDebug() << "Group name and document name are empty in UBPersistenceManager::createDocumentProxiesStructure()"; - continue; - } + QString docGroupName = metadatas.value(UBSettings::documentGroupName, QString()).toString(); + QString docName = metadatas.value(UBSettings::documentName, QString()).toString(); - QModelIndex parentIndex = mDocumentTreeStructureModel->goTo(docGroupName); - if (!parentIndex.isValid()) { - return; - } + if (docName.isEmpty()) { + qDebug() << "Group name and document name are empty in UBPersistenceManager::createDocumentProxiesStructure()"; + return; + } - UBDocumentProxy* docProxy = new UBDocumentProxy(fullPath); // managed in UBDocumentTreeNode - foreach(QString key, metadatas.keys()) { - docProxy->setMetaData(key, metadatas.value(key)); - } + QModelIndex parentIndex = mDocumentTreeStructureModel->goTo(docGroupName); + if (!parentIndex.isValid()) { + return; + } - docProxy->setPageCount(sceneCount(docProxy)); + UBDocumentProxy* docProxy = new UBDocumentProxy(fullPath, metadatas); // managed in UBDocumentTreeNode + foreach(QString key, metadatas.keys()) { + docProxy->setMetaData(key, metadatas.value(key)); + } - if (!interactive) - mDocumentTreeStructureModel->addDocument(docProxy, parentIndex); - else - processInteractiveReplacementDialog(docProxy); + if (metadatas.contains(UBSettings::documentPageCount)) + { + docProxy->setPageCount(metadatas.value(UBSettings::documentPageCount).toInt()); + } + else + { + int pageCount = sceneCount(docProxy); + docProxy->setPageCount(pageCount); } + + if (!interactive) + mDocumentTreeStructureModel->addDocument(docProxy, parentIndex); + else + processInteractiveReplacementDialog(docProxy); } } diff --git a/src/core/UBSettings.cpp b/src/core/UBSettings.cpp index 5d5cb705..e7a91017 100644 --- a/src/core/UBSettings.cpp +++ b/src/core/UBSettings.cpp @@ -60,6 +60,7 @@ QString UBSettings::documentSize = QString("Size"); QString UBSettings::documentIdentifer = QString("ID"); QString UBSettings::documentVersion = QString("Version"); QString UBSettings::documentUpdatedAt = QString("UpdatedAt"); +QString UBSettings::documentPageCount = QString("PageCount"); QString UBSettings::documentDate = QString("date"); QString UBSettings::trashedDocumentGroupNamePrefix = QString("_Trash:"); diff --git a/src/core/UBSettings.h b/src/core/UBSettings.h index a5e6d109..c79e4f95 100644 --- a/src/core/UBSettings.h +++ b/src/core/UBSettings.h @@ -201,6 +201,7 @@ class UBSettings : public QObject static QString documentIdentifer; static QString documentVersion; static QString documentUpdatedAt; + static QString documentPageCount; static QString documentDate; diff --git a/src/document/UBDocumentProxy.cpp b/src/document/UBDocumentProxy.cpp index 6f9aa711..0bf6e565 100644 --- a/src/document/UBDocumentProxy.cpp +++ b/src/document/UBDocumentProxy.cpp @@ -56,7 +56,6 @@ UBDocumentProxy::UBDocumentProxy(const UBDocumentProxy &rValue) : mPageCount = rValue.mPageCount; } - UBDocumentProxy::UBDocumentProxy(const QString& pPersistancePath) : mPageCount(0) , mPageDpi(0) @@ -68,6 +67,17 @@ UBDocumentProxy::UBDocumentProxy(const QString& pPersistancePath) } +UBDocumentProxy::UBDocumentProxy(const QString& pPersistancePath, QMap metadatas) + : mPageCount(0) + , mPageDpi(0) +{ + init(); + setPersistencePath(pPersistancePath); + + mMetaDatas = metadatas; +} + + void UBDocumentProxy::init() { setMetaData(UBSettings::documentGroupName, ""); diff --git a/src/document/UBDocumentProxy.h b/src/document/UBDocumentProxy.h index cb507dec..dfff6908 100644 --- a/src/document/UBDocumentProxy.h +++ b/src/document/UBDocumentProxy.h @@ -49,6 +49,7 @@ class UBDocumentProxy : public QObject UBDocumentProxy(); UBDocumentProxy(const UBDocumentProxy &rValue); UBDocumentProxy(const QString& pPersistencePath); + UBDocumentProxy(const QString& pPersistencePath, QMap metadatas); virtual ~UBDocumentProxy();