Optimize the process of Qsettings.setValue().

This commit is contained in:
rookie-J 2021-05-12 15:01:20 +08:00
parent 550681b38f
commit 546f80af48
5 changed files with 42 additions and 24 deletions

View File

@ -252,17 +252,22 @@ void GlobalSettings::setValue(const QString &key, const QVariant &value) {
// qDebug()<<"setvalue========"<<key<<":"<<value;
m_cache.insert(key, value);
// m_settings->sync();
QtConcurrent::run([ = ]() {
// QtConcurrent::run([ = ]() {
// qDebug()<<m_settings->status();
// if (m_mutex.tryLock(1000)) {
// m_mutex.lock();
// test++;
// qDebug()<<"QtConcurrent::run=========start!!!"<<key<<":"<<value<<test<<QTime::currentTime();
m_settings->setValue(key, value);
// qDebug()<<"setvalue========finish!!!"<<key<<":"<<value;
// qDebug()<<"QtConcurrent::run=========sync!!!";
m_settings->sync();
// qDebug()<<"QtConcurrent::run========finished!!!"<<key<<":"<<value<<test<<QTime::currentTime();
// qDebug()<<"setvalue========sync!!!"<<key<<":"<<value;
// m_mutex.unlock();
// }
});
// });
}
void GlobalSettings::forceSync(const QString &key) {

View File

@ -105,6 +105,8 @@ private:
QStringList m_history;
QMutex m_mutex;
// size_t test = 0;
};

View File

@ -82,7 +82,8 @@ void FirstIndex::run() {
} else {
this->bool_dataBaseExist = true;
}
if(indexDataBaseStatus != "2" || contentIndexDataBaseStatus != "2" || inotifyIndexStatus != "2") {
// if(indexDataBaseStatus != "2" || contentIndexDataBaseStatus != "2" || inotifyIndexStatus != "2") {
if(indexDataBaseStatus == "1" or contentIndexDataBaseStatus == "1" or inotifyIndexStatus != "2"){
this->bool_dataBaseStatusOK = false;
} else {
this->bool_dataBaseStatusOK = true;
@ -196,6 +197,8 @@ void FirstIndex::run() {
delete p_indexGenerator;
p_indexGenerator = nullptr;
// GlobalSettings::getInstance()->forceSync();
GlobalSettings::getInstance()->setValue(INDEX_DATABASE_STATE, "2");
GlobalSettings::getInstance()->setValue(CONTENT_INDEX_DATABASE_STATE, "2");
::_exit(0);
} else if(pid < 0) {
qWarning() << "First Index fork error!!";
@ -204,7 +207,6 @@ void FirstIndex::run() {
--FileUtils::_index_status;
}
GlobalSettings::getInstance()->setValue(INOTIFY_NORMAL_EXIT, "2");
int retval1 = write(fifo_fd, buffer, strlen(buffer));
if(retval1 == -1) {

View File

@ -69,7 +69,7 @@ bool IndexGenerator::creatAllIndex(QQueue<QVector<QString> > *messageList) {
return false;
}
qDebug() << "begin creatAllIndex";
GlobalSettings::getInstance()->setValue(INDEX_DATABASE_STATE, "0");
// GlobalSettings::getInstance()->setValue(INDEX_DATABASE_STATE, "0");
try {
// m_indexer = new Xapian::TermGenerator();
// m_indexer.set_database(*m_database_path);
@ -95,7 +95,7 @@ bool IndexGenerator::creatAllIndex(QQueue<QVector<QString> > *messageList) {
// FileUtils::_index_status &= ~0x1;
assert(false);
}
GlobalSettings::getInstance()->setValue(INDEX_DATABASE_STATE, "2");
// GlobalSettings::getInstance()->setValue(INDEX_DATABASE_STATE, "2");
qDebug() << "finish creatAllIndex";
// FileUtils::_index_status &= ~0x1;
_doc_list_path->clear();
@ -114,7 +114,7 @@ bool IndexGenerator::creatAllIndex(QQueue<QString> *messageList) {
int size = _doc_list_content->size();
qDebug() << "begin creatAllIndex for content" << size;
if(!size == 0) {
GlobalSettings::getInstance()->setValue(CONTENT_INDEX_DATABASE_STATE, "0");
// GlobalSettings::getInstance()->setValue(CONTENT_INDEX_DATABASE_STATE, "0");
try {
int count = 0;
for(auto i : *_doc_list_content) {
@ -131,7 +131,7 @@ bool IndexGenerator::creatAllIndex(QQueue<QString> *messageList) {
// FileUtils::_index_status &= ~0x2;
assert(false);
}
GlobalSettings::getInstance()->setValue(CONTENT_INDEX_DATABASE_STATE, "2");
// GlobalSettings::getInstance()->setValue(CONTENT_INDEX_DATABASE_STATE, "2");
// FileUtils::_index_status &= ~0x2;
qDebug() << "finish creatAllIndex for content";
_doc_list_content->clear();

View File

@ -180,12 +180,14 @@ void InotifyIndex::eventProcess(const char* buf, ssize_t tmp) {
ssize_t numRead = 0;
numRead = tmp;
char * p = const_cast<char*>(buf);
GlobalSettings::getInstance()->setValue(INOTIFY_NORMAL_EXIT, "0");
for(; p < buf + numRead;) {
struct inotify_event * event = reinterpret_cast<inotify_event *>(p);
if(event->name[0] != '.') {
qDebug() << "Read Event event->wd: " << event->wd;
qDebug() << "Read Event: " << currentPath[event->wd] << QString(event->name) << event->cookie << event->wd << event->mask;
if(event->name[0] != '.') {
qDebug() << QString(currentPath[event->wd] + '/' + event->name);
// switch (event->mask) {
if(event->mask & IN_CREATE) {
@ -235,7 +237,7 @@ void InotifyIndex::eventProcess(const char* buf, ssize_t tmp) {
next:
p += sizeof(struct inotify_event) + event->len;
}
GlobalSettings::getInstance()->setValue(INOTIFY_NORMAL_EXIT, "2");
delete indexQueue;
indexQueue = nullptr;
delete contentIndexQueue;
@ -288,14 +290,13 @@ void InotifyIndex::run() {
assert(false);
}
char * tmp = const_cast<char*>(buf);
for(; tmp < buf + numRead;) {
struct inotify_event * event = reinterpret_cast<inotify_event *>(tmp);
// qDebug() << "Read Event: " << currentPath[event->wd] << QString(event->name) << event->cookie << event->wd << event->mask;
if(event->name[0] != '.') {
GlobalSettings::getInstance()->setValue(INOTIFY_NORMAL_EXIT, "0");
// qDebug() << "Read Event: " << currentPath[event->wd] << QString(event->name) << event->cookie << event->wd << event->mask;
// qDebug("mask:0x%x,",event->mask);
break;
}
tmp += sizeof(struct inotify_event) + event->len;
@ -318,7 +319,6 @@ void InotifyIndex::run() {
qDebug() << "read";
}
eventProcess(buf, numRead);
GlobalSettings::getInstance()->setValue(INOTIFY_NORMAL_EXIT, "2");
fd_set read_fds;
int rc;
@ -343,7 +343,6 @@ void InotifyIndex::run() {
// GlobalSettings::getInstance()->forceSync();
::_exit(0);
} else {
GlobalSettings::getInstance()->setValue(INOTIFY_NORMAL_EXIT, "0");
memset(buf, 0x00, BUF_LEN);
numRead = read(m_fd, buf, BUF_LEN);
if(numRead == -1) {
@ -351,9 +350,22 @@ void InotifyIndex::run() {
fflush(stdout);
assert(false);
}
char * tmp = const_cast<char*>(buf);
for(; tmp < buf + numRead; ) {
struct inotify_event * event = reinterpret_cast<inotify_event *>(tmp);
if(event->name[0] != '.') {
break;
}
tmp += sizeof(struct inotify_event) + event->len;
}
if(tmp >= buf + numRead) {
continue;
}
qDebug() << "Read " << numRead << " bytes from inotify fd";
this->eventProcess(buf, numRead);
GlobalSettings::getInstance()->setValue(INOTIFY_NORMAL_EXIT, "2");
}
}
} else if(pid > 0) {
@ -369,7 +381,4 @@ void InotifyIndex::run() {
GlobalSettings::getInstance()->setValue(INOTIFY_NORMAL_EXIT, "3");
RemoveWatch(QStandardPaths::writableLocation(QStandardPaths::HomeLocation), false);
}
}