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. 58
      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);
selectedDocument()->setMetaData(UBSettings::documentUpdatedAt, UBStringUtils::toUtcIsoDateTime(QDateTime::currentDateTime()));
UBMetadataDcSubsetAdaptor::persist(selectedDocument());
UBPersistenceManager::persistenceManager()->persistDocumentMetadata(selectedDocument());
mMovingSceneIndex = source;
setActiveDocumentScene(target);
mMovingSceneIndex = -1;

@ -79,14 +79,33 @@ UBPersistenceManager::UBPersistenceManager(QObject *pParent)
mThread = new QThread;
mWorker = new UBPersistenceWorker();
mWorker->moveToThread(mThread);
connect(mWorker, SIGNAL(error(QString)), this, SLOT(errorString(QString)));
connect(mThread, SIGNAL(started()), mWorker, SLOT(process()));
connect(mWorker, SIGNAL(finished()), 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(error(QString)),
this, SLOT(errorString(QString)));
connect(mThread, SIGNAL(started()),
mWorker, SLOT(process()));
connect(mWorker, SIGNAL(finished()),
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();
}
@ -114,6 +133,11 @@ void UBPersistenceManager::onScenePersisted(UBGraphicsScene* scene)
scene = NULL;
}
void UBPersistenceManager::onMetadataPersisted(UBDocumentProxy* proxy)
{
delete proxy;
}
void UBPersistenceManager::onWorkerFinished()
{
mIsWorkerFinished = true;
@ -752,14 +776,14 @@ void UBPersistenceManager::persistDocumentScene(UBDocumentProxy* pDocumentProxy,
mSceneCache.insert(pDocumentProxy, pSceneIndex, pScene);
if (pDocumentProxy->isModified())
UBMetadataDcSubsetAdaptor::persist(pDocumentProxy);
persistDocumentMetadata(pDocumentProxy, forceImmediateSaving);
if (pScene->isModified())
{
UBThumbnailAdaptor::persistScene(pDocumentProxy, pScene, pSceneIndex);
if(forceImmediateSaving)
UBSvgSubsetAdaptor::persistScene(pDocumentProxy,pScene,pSceneIndex);
else{
else {
UBGraphicsScene* copiedScene = pScene->sceneDeepCopy();
mWorker->saveScene(pDocumentProxy, copiedScene, pSceneIndex);
pScene->setModified(false);
@ -769,13 +793,17 @@ void UBPersistenceManager::persistDocumentScene(UBDocumentProxy* pDocumentProxy,
}
UBDocumentProxy* UBPersistenceManager::persistDocumentMetadata(UBDocumentProxy* pDocumentProxy)
void UBPersistenceManager::persistDocumentMetadata(UBDocumentProxy* pDocumentProxy, bool forceImmediateSaving)
{
UBMetadataDcSubsetAdaptor::persist(pDocumentProxy);
emit documentMetadataChanged(pDocumentProxy);
if (forceImmediateSaving) {
UBMetadataDcSubsetAdaptor::persist(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* 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);
@ -161,6 +161,7 @@ class UBPersistenceManager : public QObject
void onSceneLoaded(QByteArray,UBDocumentProxy*,int);
void onWorkerFinished();
void onScenePersisted(UBGraphicsScene* scene);
void onMetadataPersisted(UBDocumentProxy* proxy);
};

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

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

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

@ -69,6 +69,16 @@ UBDocumentProxy::~UBDocumentProxy()
// 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()
{

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

Loading…
Cancel
Save