Optimized index status record mechanism.
This commit is contained in:
parent
546f80af48
commit
5ff0d20b1f
|
@ -40,8 +40,10 @@ unix {
|
|||
!isEmpty(target.path): INSTALLS += target
|
||||
|
||||
header.path = /usr/include/chinese-seg/
|
||||
header.files += *.h cppjieba/*
|
||||
INSTALLS += header header_cppjieba
|
||||
header.files += *.h
|
||||
headercppjieba.path = /usr/include/chinese-seg/cppjieba/
|
||||
headercppjieba.files = cppjieba/*
|
||||
INSTALLS += header headercppjieba
|
||||
|
||||
#DISTFILES += \
|
||||
# jiaba/jieba.pri
|
||||
|
|
|
@ -0,0 +1,7 @@
|
|||
#ifndef COMMON_H
|
||||
#define COMMON_H
|
||||
|
||||
#define UKUI_SEARCH_PIPE_PATH (QDir::homePath()+"/.config/org.ukui/ukui-search/ukuisearch").toLocal8Bit().constData()
|
||||
|
||||
//TODO Put things that needed to be put here here.
|
||||
#endif // COMMON_H
|
|
@ -56,8 +56,6 @@
|
|||
//#define FINISH_CREATING_INDEX 2
|
||||
#define MAX_CONTENT_LENGTH 20480000
|
||||
|
||||
#define UKUI_SEARCH_PIPE_PATH (QDir::homePath()+"/.config/org.ukui/ukui-search/ukuisearch").toLocal8Bit().constData()
|
||||
|
||||
namespace Zeeker {
|
||||
class LIBSEARCH_EXPORT FileUtils {
|
||||
public:
|
||||
|
|
|
@ -246,28 +246,16 @@ QStringList GlobalSettings::getSearchRecord() {
|
|||
// return values;
|
||||
//}
|
||||
|
||||
//here should be override
|
||||
//MouseZhangZh
|
||||
//this method is designed for main process settings only!!
|
||||
void GlobalSettings::setValue(const QString &key, const QVariant &value) {
|
||||
// qDebug()<<"setvalue========"<<key<<":"<<value;
|
||||
m_cache.insert(key, value);
|
||||
// m_settings->sync();
|
||||
// QtConcurrent::run([ = ]() {
|
||||
// qDebug()<<m_settings->status();
|
||||
// if (m_mutex.tryLock(1000)) {
|
||||
// m_mutex.lock();
|
||||
|
||||
// test++;
|
||||
// qDebug()<<"QtConcurrent::run=========start!!!"<<key<<":"<<value<<test<<QTime::currentTime();
|
||||
QtConcurrent::run([ = ]() {
|
||||
if (m_mutex.tryLock(1000)) {
|
||||
m_settings->setValue(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();
|
||||
// }
|
||||
// });
|
||||
m_mutex.unlock();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
void GlobalSettings::forceSync(const QString &key) {
|
||||
|
|
|
@ -40,10 +40,7 @@
|
|||
#define THEME_GSETTINGS_ID "org.ukui.style"
|
||||
#define STYLE_NAME_KEY "styleName"
|
||||
#define FONT_SIZE_KEY "systemFontSize"
|
||||
#define INDEX_DATABASE_STATE "index_database_state"
|
||||
#define CONTENT_INDEX_DATABASE_STATE "content_index_database_state"
|
||||
#define INDEX_GENERATOR_NORMAL_EXIT "index_generator_normal_exit"
|
||||
#define INOTIFY_NORMAL_EXIT "inotify_normal_exit"
|
||||
|
||||
#define ENABLE_CREATE_INDEX_ASK_DIALOG "enable_create_index_ask_dialog"
|
||||
#define WEB_ENGINE "web_engine"
|
||||
#define PATH_EMPTY 1;
|
||||
|
|
|
@ -68,9 +68,9 @@ void FirstIndex::run() {
|
|||
}
|
||||
qDebug() << "create fifo success\n";
|
||||
|
||||
QString indexDataBaseStatus = GlobalSettings::getInstance()->getValue(INDEX_DATABASE_STATE).toString();
|
||||
QString contentIndexDataBaseStatus = GlobalSettings::getInstance()->getValue(CONTENT_INDEX_DATABASE_STATE).toString();
|
||||
QString inotifyIndexStatus = GlobalSettings::getInstance()->getValue(INOTIFY_NORMAL_EXIT).toString();
|
||||
QString indexDataBaseStatus = IndexStatusRecorder::getInstance()->getStatus(INDEX_DATABASE_STATE).toString();
|
||||
QString contentIndexDataBaseStatus = IndexStatusRecorder::getInstance()->getStatus(CONTENT_INDEX_DATABASE_STATE).toString();
|
||||
QString inotifyIndexStatus = IndexStatusRecorder::getInstance()->getStatus(INOTIFY_NORMAL_EXIT).toString();
|
||||
|
||||
qDebug() << "indexDataBaseStatus: " << indexDataBaseStatus;
|
||||
qDebug() << "contentIndexDataBaseStatus: " << contentIndexDataBaseStatus;
|
||||
|
@ -82,8 +82,7 @@ void FirstIndex::run() {
|
|||
} else {
|
||||
this->bool_dataBaseExist = true;
|
||||
}
|
||||
// if(indexDataBaseStatus != "2" || contentIndexDataBaseStatus != "2" || inotifyIndexStatus != "2") {
|
||||
if(indexDataBaseStatus == "1" or contentIndexDataBaseStatus == "1" or inotifyIndexStatus != "2"){
|
||||
if(indexDataBaseStatus != "2" || contentIndexDataBaseStatus != "2" || inotifyIndexStatus != "2") {
|
||||
this->bool_dataBaseStatusOK = false;
|
||||
} else {
|
||||
this->bool_dataBaseStatusOK = true;
|
||||
|
@ -197,8 +196,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");
|
||||
IndexStatusRecorder::getInstance()->setStatus(INDEX_DATABASE_STATE, "2");
|
||||
IndexStatusRecorder::getInstance()->setStatus(CONTENT_INDEX_DATABASE_STATE, "2");
|
||||
::_exit(0);
|
||||
} else if(pid < 0) {
|
||||
qWarning() << "First Index fork error!!";
|
||||
|
@ -207,7 +206,7 @@ void FirstIndex::run() {
|
|||
--FileUtils::_index_status;
|
||||
}
|
||||
|
||||
GlobalSettings::getInstance()->setValue(INOTIFY_NORMAL_EXIT, "2");
|
||||
IndexStatusRecorder::getInstance()->setStatus(INOTIFY_NORMAL_EXIT, "2");
|
||||
int retval1 = write(fifo_fd, buffer, strlen(buffer));
|
||||
if(retval1 == -1) {
|
||||
qWarning("write error\n");
|
||||
|
|
|
@ -37,11 +37,11 @@
|
|||
#include <syslog.h>
|
||||
//#include <QtConcurrent>
|
||||
#include "traverse_bfs.h"
|
||||
#include "global-settings.h"
|
||||
#include "index-status-recorder.h"
|
||||
#include "index-generator.h"
|
||||
#include "inotify-index.h"
|
||||
#include "file-utils.h"
|
||||
|
||||
#include "common.h"
|
||||
namespace Zeeker {
|
||||
class FirstIndex : public QThread, public Traverse_BFS {
|
||||
public:
|
||||
|
|
|
@ -27,7 +27,6 @@
|
|||
#include <QFile>
|
||||
#include "file-utils.h"
|
||||
#include "index-generator.h"
|
||||
#include "global-settings.h"
|
||||
#include "chinese-segmentation.h"
|
||||
#include "construct-document.h"
|
||||
#include <QStandardPaths>
|
||||
|
@ -91,7 +90,7 @@ bool IndexGenerator::creatAllIndex(QQueue<QVector<QString> > *messageList) {
|
|||
} catch(const Xapian::Error &e) {
|
||||
qWarning() << "creatAllIndex fail!" << QString::fromStdString(e.get_description());
|
||||
//need a record
|
||||
GlobalSettings::getInstance()->setValue(INDEX_DATABASE_STATE, "1");
|
||||
IndexStatusRecorder::getInstance()->setStatus(INDEX_DATABASE_STATE, "1");
|
||||
// FileUtils::_index_status &= ~0x1;
|
||||
assert(false);
|
||||
}
|
||||
|
@ -127,7 +126,7 @@ bool IndexGenerator::creatAllIndex(QQueue<QString> *messageList) {
|
|||
m_database_content->commit();
|
||||
} catch(const Xapian::Error &e) {
|
||||
qWarning() << "creat content Index fail!" << QString::fromStdString(e.get_description());
|
||||
GlobalSettings::getInstance()->setValue(CONTENT_INDEX_DATABASE_STATE, "1");
|
||||
IndexStatusRecorder::getInstance()->setStatus(CONTENT_INDEX_DATABASE_STATE, "1");
|
||||
// FileUtils::_index_status &= ~0x2;
|
||||
assert(false);
|
||||
}
|
||||
|
|
|
@ -29,8 +29,10 @@
|
|||
#include <QMutex>
|
||||
#include <QQueue>
|
||||
//#include <QMetaObject>
|
||||
#include "index-status-recorder.h"
|
||||
#include "document.h"
|
||||
#include "file-reader.h"
|
||||
#include "common.h"
|
||||
|
||||
namespace Zeeker {
|
||||
extern QList<Document> *_doc_list_path;
|
||||
|
|
|
@ -0,0 +1,28 @@
|
|||
#include "index-status-recorder.h"
|
||||
|
||||
using namespace Zeeker;
|
||||
static IndexStatusRecorder *global_instance_indexStatusRecorder = nullptr;
|
||||
|
||||
IndexStatusRecorder *IndexStatusRecorder::getInstance()
|
||||
{
|
||||
if(!global_instance_indexStatusRecorder) {
|
||||
global_instance_indexStatusRecorder = new IndexStatusRecorder;
|
||||
}
|
||||
return global_instance_indexStatusRecorder;
|
||||
}
|
||||
|
||||
void IndexStatusRecorder::setStatus(const QString &key, const QVariant &value)
|
||||
{
|
||||
m_status->setValue(key, value);
|
||||
m_status->sync();
|
||||
}
|
||||
|
||||
const QVariant IndexStatusRecorder::getStatus(const QString &key)
|
||||
{
|
||||
return m_status->value(key);
|
||||
}
|
||||
|
||||
IndexStatusRecorder::IndexStatusRecorder(QObject *parent) : QObject(parent)
|
||||
{
|
||||
m_status = new QSettings(INDEX_STATUS, QSettings::IniFormat, this);
|
||||
}
|
|
@ -0,0 +1,27 @@
|
|||
#ifndef INDEXSTATUSRECORDER_H
|
||||
#define INDEXSTATUSRECORDER_H
|
||||
|
||||
#include <QObject>
|
||||
#include <QSettings>
|
||||
#include <QDir>
|
||||
#define CONTENT_INDEX_DATABASE_STATE "content_index_database_state"
|
||||
#define INDEX_DATABASE_STATE "index_database_state"
|
||||
#define INOTIFY_NORMAL_EXIT "inotify_normal_exit"
|
||||
#define INDEX_STATUS QDir::homePath() + "/.config/org.ukui/ukui-search/ukui-search-index-status.conf"
|
||||
namespace Zeeker {
|
||||
//fixme: we need a better way to record index status.
|
||||
class IndexStatusRecorder : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
static IndexStatusRecorder *getInstance();
|
||||
void setStatus(const QString& key, const QVariant& value);
|
||||
const QVariant getStatus(const QString& key);
|
||||
|
||||
private:
|
||||
explicit IndexStatusRecorder(QObject *parent = nullptr);
|
||||
QSettings *m_status;
|
||||
};
|
||||
}
|
||||
|
||||
#endif // INDEXSTATUSRECORDER_H
|
|
@ -6,6 +6,7 @@ HEADERS += \
|
|||
$$PWD/file-reader.h \
|
||||
$$PWD/first-index.h \
|
||||
$$PWD/index-generator.h \
|
||||
$$PWD/index-status-recorder.h \
|
||||
$$PWD/inotify-index.h \
|
||||
$$PWD/search-manager.h \
|
||||
$$PWD/searchmethodmanager.h \
|
||||
|
@ -18,6 +19,7 @@ SOURCES += \
|
|||
$$PWD/file-reader.cpp \
|
||||
$$PWD/first-index.cpp \
|
||||
$$PWD/index-generator.cpp \
|
||||
$$PWD/index-status-recorder.cpp \
|
||||
$$PWD/inotify-index.cpp \
|
||||
$$PWD/search-manager.cpp \
|
||||
$$PWD/searchmethodmanager.cpp \
|
||||
|
|
|
@ -180,7 +180,7 @@ 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");
|
||||
IndexStatusRecorder::getInstance()->setStatus(INOTIFY_NORMAL_EXIT, "0");
|
||||
for(; p < buf + numRead;) {
|
||||
struct inotify_event * event = reinterpret_cast<inotify_event *>(p);
|
||||
if(event->name[0] != '.') {
|
||||
|
@ -237,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");
|
||||
IndexStatusRecorder::getInstance()->setStatus(INOTIFY_NORMAL_EXIT, "2");
|
||||
delete indexQueue;
|
||||
indexQueue = nullptr;
|
||||
delete contentIndexQueue;
|
||||
|
@ -285,11 +285,12 @@ void InotifyIndex::run() {
|
|||
|
||||
if(numRead == -1) {
|
||||
printf("\033[1;31;40mread event error\033[0m\n");
|
||||
GlobalSettings::getInstance()->setValue(INOTIFY_NORMAL_EXIT, "1");
|
||||
IndexStatusRecorder::getInstance()->setStatus(INOTIFY_NORMAL_EXIT, "1");
|
||||
fflush(stdout);
|
||||
assert(false);
|
||||
}
|
||||
|
||||
//TODO: Merge multiple signals.
|
||||
char * tmp = const_cast<char*>(buf);
|
||||
|
||||
for(; tmp < buf + numRead;) {
|
||||
|
@ -334,7 +335,7 @@ void InotifyIndex::run() {
|
|||
if(rc < 0) {
|
||||
// error
|
||||
qWarning() << "select result < 0, error!";
|
||||
GlobalSettings::getInstance()->setValue(INOTIFY_NORMAL_EXIT, "1");
|
||||
IndexStatusRecorder::getInstance()->setStatus(INOTIFY_NORMAL_EXIT, "1");
|
||||
assert(false);
|
||||
} else if(rc == 0) {
|
||||
qDebug() << "select timeout!";
|
||||
|
@ -351,6 +352,7 @@ void InotifyIndex::run() {
|
|||
assert(false);
|
||||
}
|
||||
|
||||
//TODO: Merge multiple signals.
|
||||
char * tmp = const_cast<char*>(buf);
|
||||
|
||||
for(; tmp < buf + numRead; ) {
|
||||
|
@ -378,7 +380,7 @@ void InotifyIndex::run() {
|
|||
}
|
||||
|
||||
if(FileUtils::SearchMethod::DIRECTSEARCH == FileUtils::searchMethod) {
|
||||
GlobalSettings::getInstance()->setValue(INOTIFY_NORMAL_EXIT, "3");
|
||||
IndexStatusRecorder::getInstance()->setStatus(INOTIFY_NORMAL_EXIT, "3");
|
||||
RemoveWatch(QStandardPaths::writableLocation(QStandardPaths::HomeLocation), false);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -27,9 +27,10 @@
|
|||
#include "index-generator.h"
|
||||
#include "traverse_bfs.h"
|
||||
#include "ukui-search-qdbus.h"
|
||||
#include "global-settings.h"
|
||||
#include "index-status-recorder.h"
|
||||
#include "file-utils.h"
|
||||
#include "first-index.h"
|
||||
#include "common.h"
|
||||
|
||||
#define BUF_LEN 1024000
|
||||
|
||||
|
|
|
@ -3,7 +3,6 @@
|
|||
|
||||
#include "first-index.h"
|
||||
#include "inotify-index.h"
|
||||
|
||||
namespace Zeeker {
|
||||
class SearchMethodManager {
|
||||
public:
|
||||
|
|
|
@ -42,6 +42,7 @@ SOURCES += \
|
|||
libsearch.cpp
|
||||
|
||||
HEADERS += \
|
||||
common.h \
|
||||
file-utils.h \
|
||||
global-settings.h \
|
||||
gobject-template.h \
|
||||
|
|
Loading…
Reference in New Issue