Moved document metadata saving to UBPersistenceManager's worker thread

(Reading is still done synchronously, for now at least)
preferencesAboutTextFull
Craig Watson 9 years ago
parent 46ce553d75
commit 59207cbbf2
  1. 2
      src/board/UBBoardController.cpp
  2. 52
      src/core/UBPersistenceManager.cpp
  3. 3
      src/core/UBPersistenceManager.h
  4. 16
      src/core/UBPersistenceWorker.cpp
  5. 5
      src/core/UBPersistenceWorker.h
  6. 16
      src/document/UBDocumentController.cpp
  7. 10
      src/document/UBDocumentProxy.cpp
  8. 2
      src/document/UBDocumentProxy.h

@ -1552,7 +1552,7 @@ void UBBoardController::moveSceneToIndex(int source, int target)
UBDocumentContainer::movePageToIndex(source, target); UBDocumentContainer::movePageToIndex(source, target);
selectedDocument()->setMetaData(UBSettings::documentUpdatedAt, UBStringUtils::toUtcIsoDateTime(QDateTime::currentDateTime())); selectedDocument()->setMetaData(UBSettings::documentUpdatedAt, UBStringUtils::toUtcIsoDateTime(QDateTime::currentDateTime()));
UBMetadataDcSubsetAdaptor::persist(selectedDocument()); UBPersistenceManager::persistenceManager()->persistDocumentMetadata(selectedDocument());
mMovingSceneIndex = source; mMovingSceneIndex = source;
setActiveDocumentScene(target); setActiveDocumentScene(target);
mMovingSceneIndex = -1; mMovingSceneIndex = -1;

@ -79,14 +79,33 @@ UBPersistenceManager::UBPersistenceManager(QObject *pParent)
mThread = new QThread; mThread = new QThread;
mWorker = new UBPersistenceWorker(); mWorker = new UBPersistenceWorker();
mWorker->moveToThread(mThread); mWorker->moveToThread(mThread);
connect(mWorker, SIGNAL(error(QString)), this, SLOT(errorString(QString))); connect(mWorker, SIGNAL(error(QString)),
connect(mThread, SIGNAL(started()), mWorker, SLOT(process())); this, SLOT(errorString(QString)));
connect(mWorker, SIGNAL(finished()), mThread, SLOT(quit()));
connect(mWorker, SIGNAL(finished()), this, SLOT(onWorkerFinished())); connect(mThread, SIGNAL(started()),
connect(mWorker, SIGNAL(finished()), mWorker, SLOT(deleteLater())); mWorker, SLOT(process()));
connect(mThread, SIGNAL(finished()), mThread, SLOT(deleteLater()));
connect(mWorker,SIGNAL(sceneLoaded(QByteArray,UBDocumentProxy*,int)),this,SLOT(onSceneLoaded(QByteArray,UBDocumentProxy*,int))); connect(mWorker, SIGNAL(finished()),
connect(mWorker,SIGNAL(scenePersisted(UBGraphicsScene*)),this,SLOT(onScenePersisted(UBGraphicsScene*))); mThread, SLOT(quit()));
connect(mWorker, SIGNAL(finished()),
this, SLOT(onWorkerFinished()));
connect(mWorker, SIGNAL(finished()),
mWorker, SLOT(deleteLater()));
connect(mThread, SIGNAL(finished()),
mThread, SLOT(deleteLater()));
connect(mWorker, SIGNAL(sceneLoaded(QByteArray,UBDocumentProxy*,int)),
this, SLOT(onSceneLoaded(QByteArray,UBDocumentProxy*,int)));
connect(mWorker, SIGNAL(scenePersisted(UBGraphicsScene*)),
this, SLOT(onScenePersisted(UBGraphicsScene*)));
connect(mWorker, SIGNAL(metadataPersisted(UBDocumentProxy*)),
this, SLOT(onMetadataPersisted(UBDocumentProxy*)));
mThread->start(); mThread->start();
} }
@ -114,6 +133,11 @@ void UBPersistenceManager::onScenePersisted(UBGraphicsScene* scene)
scene = NULL; scene = NULL;
} }
void UBPersistenceManager::onMetadataPersisted(UBDocumentProxy* proxy)
{
delete proxy;
}
void UBPersistenceManager::onWorkerFinished() void UBPersistenceManager::onWorkerFinished()
{ {
mIsWorkerFinished = true; mIsWorkerFinished = true;
@ -752,7 +776,7 @@ void UBPersistenceManager::persistDocumentScene(UBDocumentProxy* pDocumentProxy,
mSceneCache.insert(pDocumentProxy, pSceneIndex, pScene); mSceneCache.insert(pDocumentProxy, pSceneIndex, pScene);
if (pDocumentProxy->isModified()) if (pDocumentProxy->isModified())
UBMetadataDcSubsetAdaptor::persist(pDocumentProxy); persistDocumentMetadata(pDocumentProxy, forceImmediateSaving);
if (pScene->isModified()) if (pScene->isModified())
{ {
@ -769,13 +793,17 @@ void UBPersistenceManager::persistDocumentScene(UBDocumentProxy* pDocumentProxy,
} }
UBDocumentProxy* UBPersistenceManager::persistDocumentMetadata(UBDocumentProxy* pDocumentProxy) void UBPersistenceManager::persistDocumentMetadata(UBDocumentProxy* pDocumentProxy, bool forceImmediateSaving)
{ {
if (forceImmediateSaving) {
UBMetadataDcSubsetAdaptor::persist(pDocumentProxy); UBMetadataDcSubsetAdaptor::persist(pDocumentProxy);
emit documentMetadataChanged(pDocumentProxy); emit documentMetadataChanged(pDocumentProxy);
}
return pDocumentProxy; else {
UBDocumentProxy* copy = pDocumentProxy->deepCopy();
mWorker->saveMetadata(copy);
}
} }

@ -64,7 +64,7 @@ class UBPersistenceManager : public QObject
virtual UBDocumentProxy* createDocument(const QString& pGroupName = "", const QString& pName = "", bool withEmptyPage = true); virtual UBDocumentProxy* createDocument(const QString& pGroupName = "", const QString& pName = "", bool withEmptyPage = true);
virtual UBDocumentProxy* createDocumentFromDir(const QString& pDocumentDirectory, const QString& pGroupName = "", const QString& pName = ""); virtual UBDocumentProxy* createDocumentFromDir(const QString& pDocumentDirectory, const QString& pGroupName = "", const QString& pName = "");
virtual UBDocumentProxy* persistDocumentMetadata(UBDocumentProxy* pDocumentProxy); virtual void persistDocumentMetadata(UBDocumentProxy* pDocumentProxy, bool forceImmediateSaving = false);
virtual UBDocumentProxy* duplicateDocument(UBDocumentProxy* pDocumentProxy); virtual UBDocumentProxy* duplicateDocument(UBDocumentProxy* pDocumentProxy);
@ -161,6 +161,7 @@ class UBPersistenceManager : public QObject
void onSceneLoaded(QByteArray,UBDocumentProxy*,int); void onSceneLoaded(QByteArray,UBDocumentProxy*,int);
void onWorkerFinished(); void onWorkerFinished();
void onScenePersisted(UBGraphicsScene* scene); void onScenePersisted(UBGraphicsScene* scene);
void onMetadataPersisted(UBDocumentProxy* proxy);
}; };

@ -25,6 +25,7 @@
#include "UBPersistenceWorker.h" #include "UBPersistenceWorker.h"
#include "adaptors/UBSvgSubsetAdaptor.h" #include "adaptors/UBSvgSubsetAdaptor.h"
#include "adaptors/UBThumbnailAdaptor.h" #include "adaptors/UBThumbnailAdaptor.h"
#include "adaptors/UBMetadataDcSubsetAdaptor.h"
UBPersistenceWorker::UBPersistenceWorker(QObject *parent) : UBPersistenceWorker::UBPersistenceWorker(QObject *parent) :
QObject(parent) QObject(parent)
@ -48,6 +49,13 @@ void UBPersistenceWorker::readScene(UBDocumentProxy* proxy, const int pageIndex)
mSemaphore.release(); mSemaphore.release();
} }
void UBPersistenceWorker::saveMetadata(UBDocumentProxy *proxy)
{
PersistenceInformation entry = {WriteMetadata, proxy, NULL, 0};
saves.append(entry);
mSemaphore.release();
}
void UBPersistenceWorker::applicationWillClose() void UBPersistenceWorker::applicationWillClose()
{ {
qDebug() << "applicaiton Will close signal received"; qDebug() << "applicaiton Will close signal received";
@ -65,9 +73,15 @@ void UBPersistenceWorker::process()
UBSvgSubsetAdaptor::persistScene(info.proxy, info.scene, info.sceneIndex); UBSvgSubsetAdaptor::persistScene(info.proxy, info.scene, info.sceneIndex);
emit scenePersisted(info.scene); emit scenePersisted(info.scene);
} }
else{ else if (info.action == ReadScene){
emit sceneLoaded(UBSvgSubsetAdaptor::loadSceneAsText(info.proxy,info.sceneIndex), info.proxy, info.sceneIndex); emit sceneLoaded(UBSvgSubsetAdaptor::loadSceneAsText(info.proxy,info.sceneIndex), info.proxy, info.sceneIndex);
} }
else if (info.action == WriteMetadata) {
if (info.proxy->isModified()) {
UBMetadataDcSubsetAdaptor::persist(info.proxy);
emit metadataPersisted(info.proxy);
}
}
mSemaphore.acquire(); mSemaphore.acquire();
}while(!mReceivedApplicationClosing); }while(!mReceivedApplicationClosing);
qDebug() << "process will stop"; qDebug() << "process will stop";

@ -32,7 +32,8 @@
typedef enum{ typedef enum{
WriteScene = 0, WriteScene = 0,
ReadScene ReadScene,
WriteMetadata
}ActionType; }ActionType;
typedef struct{ typedef struct{
@ -50,12 +51,14 @@ public:
void saveScene(UBDocumentProxy* proxy, UBGraphicsScene* scene, const int pageIndex); void saveScene(UBDocumentProxy* proxy, UBGraphicsScene* scene, const int pageIndex);
void readScene(UBDocumentProxy* proxy, const int pageIndex); void readScene(UBDocumentProxy* proxy, const int pageIndex);
void saveMetadata(UBDocumentProxy* proxy);
signals: signals:
void finished(); void finished();
void error(QString string); void error(QString string);
void sceneLoaded(QByteArray text,UBDocumentProxy* proxy, const int pageIndex); void sceneLoaded(QByteArray text,UBDocumentProxy* proxy, const int pageIndex);
void scenePersisted(UBGraphicsScene* scene); void scenePersisted(UBGraphicsScene* scene);
void metadataPersisted(UBDocumentProxy* proxy);
public slots: public slots:
void process(); void process();

@ -517,7 +517,7 @@ void UBDocumentController::duplicateSelectedItem()
duplicatePages(selectedSceneIndexes); duplicatePages(selectedSceneIndexes);
emit documentThumbnailsUpdated(this); emit documentThumbnailsUpdated(this);
selectedDocument()->setMetaData(UBSettings::documentUpdatedAt, UBStringUtils::toUtcIsoDateTime(QDateTime::currentDateTime())); selectedDocument()->setMetaData(UBSettings::documentUpdatedAt, UBStringUtils::toUtcIsoDateTime(QDateTime::currentDateTime()));
UBMetadataDcSubsetAdaptor::persist(selectedDocument()); UBPersistenceManager::persistenceManager()->persistDocumentMetadata(selectedDocument());
mDocumentUI->thumbnailWidget->selectItemAt(selectedSceneIndexes.last() + selectedSceneIndexes.size()); mDocumentUI->thumbnailWidget->selectItemAt(selectedSceneIndexes.last() + selectedSceneIndexes.size());
} }
} }
@ -534,7 +534,7 @@ void UBDocumentController::duplicateSelectedItem()
UBDocumentProxy* duplicatedDoc = UBPersistenceManager::persistenceManager()->duplicateDocument(source); UBDocumentProxy* duplicatedDoc = UBPersistenceManager::persistenceManager()->duplicateDocument(source);
duplicatedDoc->setMetaData(UBSettings::documentUpdatedAt, UBStringUtils::toUtcIsoDateTime(QDateTime::currentDateTime())); duplicatedDoc->setMetaData(UBSettings::documentUpdatedAt, UBStringUtils::toUtcIsoDateTime(QDateTime::currentDateTime()));
UBMetadataDcSubsetAdaptor::persist(duplicatedDoc); UBPersistenceManager::persistenceManager()->persistDocumentMetadata(duplicatedDoc);
selectDocument(duplicatedDoc, false); selectDocument(duplicatedDoc, false);
@ -1104,7 +1104,7 @@ void UBDocumentController::addFolderOfImages()
else else
{ {
document->setMetaData(UBSettings::documentUpdatedAt, UBStringUtils::toUtcIsoDateTime(QDateTime::currentDateTime())); document->setMetaData(UBSettings::documentUpdatedAt, UBStringUtils::toUtcIsoDateTime(QDateTime::currentDateTime()));
UBMetadataDcSubsetAdaptor::persist(document); UBPersistenceManager::persistenceManager()->persistDocumentMetadata(document);
reloadThumbnails(); reloadThumbnails();
} }
} }
@ -1150,7 +1150,7 @@ bool UBDocumentController::addFileToDocument(UBDocumentProxy* document)
if (success) if (success)
{ {
document->setMetaData(UBSettings::documentUpdatedAt, UBStringUtils::toUtcIsoDateTime(QDateTime::currentDateTime())); document->setMetaData(UBSettings::documentUpdatedAt, UBStringUtils::toUtcIsoDateTime(QDateTime::currentDateTime()));
UBMetadataDcSubsetAdaptor::persist(document); UBPersistenceManager::persistenceManager()->persistDocumentMetadata(document);
} }
else else
{ {
@ -1169,7 +1169,7 @@ void UBDocumentController::moveSceneToIndex(UBDocumentProxy* proxy, int source,
if (UBDocumentContainer::movePageToIndex(source, target)) if (UBDocumentContainer::movePageToIndex(source, target))
{ {
proxy->setMetaData(UBSettings::documentUpdatedAt, UBStringUtils::toUtcIsoDateTime(QDateTime::currentDateTime())); proxy->setMetaData(UBSettings::documentUpdatedAt, UBStringUtils::toUtcIsoDateTime(QDateTime::currentDateTime()));
UBMetadataDcSubsetAdaptor::persist(proxy); UBPersistenceManager::persistenceManager()->persistDocumentMetadata(proxy);
mDocumentUI->thumbnailWidget->hightlightItem(target); mDocumentUI->thumbnailWidget->hightlightItem(target);
} }
@ -1497,7 +1497,7 @@ void UBDocumentController::addToDocument()
mDocumentUI->thumbnailWidget->selectItemAt(newActiveSceneIndex, false); mDocumentUI->thumbnailWidget->selectItemAt(newActiveSceneIndex, false);
selectDocument(mBoardController->selectedDocument()); selectDocument(mBoardController->selectedDocument());
mBoardController->selectedDocument()->setMetaData(UBSettings::documentUpdatedAt, UBStringUtils::toUtcIsoDateTime(QDateTime::currentDateTime())); mBoardController->selectedDocument()->setMetaData(UBSettings::documentUpdatedAt, UBStringUtils::toUtcIsoDateTime(QDateTime::currentDateTime()));
UBMetadataDcSubsetAdaptor::persist(mBoardController->selectedDocument()); UBPersistenceManager::persistenceManager()->persistDocumentMetadata(mBoardController->selectedDocument());
UBApplication::applicationController->showBoard(); UBApplication::applicationController->showBoard();
} }
@ -1678,7 +1678,7 @@ void UBDocumentController::addImages()
else else
{ {
document->setMetaData(UBSettings::documentUpdatedAt, UBStringUtils::toUtcIsoDateTime(QDateTime::currentDateTime())); document->setMetaData(UBSettings::documentUpdatedAt, UBStringUtils::toUtcIsoDateTime(QDateTime::currentDateTime()));
UBMetadataDcSubsetAdaptor::persist(document); UBPersistenceManager::persistenceManager()->persistDocumentMetadata(document);
reloadThumbnails(); reloadThumbnails();
} }
} }
@ -1791,7 +1791,7 @@ void UBDocumentController::deletePages(QList<QGraphicsItem *> itemsToDelete)
UBDocumentContainer::deletePages(sceneIndexes); UBDocumentContainer::deletePages(sceneIndexes);
proxy->setMetaData(UBSettings::documentUpdatedAt, UBStringUtils::toUtcIsoDateTime(QDateTime::currentDateTime())); proxy->setMetaData(UBSettings::documentUpdatedAt, UBStringUtils::toUtcIsoDateTime(QDateTime::currentDateTime()));
UBMetadataDcSubsetAdaptor::persist(proxy); UBPersistenceManager::persistenceManager()->persistDocumentMetadata(proxy);
int minIndex = proxy->pageCount() - 1; int minIndex = proxy->pageCount() - 1;
foreach (int i, sceneIndexes) foreach (int i, sceneIndexes)

@ -69,6 +69,16 @@ UBDocumentProxy::~UBDocumentProxy()
// NOOP // NOOP
} }
UBDocumentProxy* UBDocumentProxy::deepCopy() const
{
UBDocumentProxy* copy = new UBDocumentProxy();
copy->mPersistencePath = QString(mPersistencePath);
copy->mMetaDatas = QHash<QString, QVariant>(mMetaDatas);
copy->mIsModified = mIsModified;
copy->mPageCount = mPageCount;
}
int UBDocumentProxy::pageCount() int UBDocumentProxy::pageCount()
{ {

@ -49,6 +49,8 @@ class UBDocumentProxy : public QObject
virtual ~UBDocumentProxy(); virtual ~UBDocumentProxy();
UBDocumentProxy * deepCopy() const;
QString persistencePath() const; QString persistencePath() const;
void setPersistencePath(const QString& pPersistencePath); void setPersistencePath(const QString& pPersistencePath);

Loading…
Cancel
Save