fix(ai-index):修复更新ai索引时的逻辑错误,优化更新速度
增量更新和实时更新将共用一个session,避免多次创建session
This commit is contained in:
parent
81ab29bb64
commit
42d3242553
|
@ -31,9 +31,11 @@ class AiIndexerPrivate
|
|||
{
|
||||
public:
|
||||
QMutex m_mutex;
|
||||
bool m_sessionValid = false;
|
||||
DataManagementSession m_session = nullptr;
|
||||
static bool m_sessionValid;
|
||||
static DataManagementSession m_session;
|
||||
};
|
||||
DataManagementSession AiIndexerPrivate::m_session = nullptr;
|
||||
bool AiIndexerPrivate::m_sessionValid = false;
|
||||
AiIndexer::AiIndexer(QObject *parent) : QObject(parent), d(new AiIndexerPrivate)
|
||||
{
|
||||
d->m_mutex.lock();
|
||||
|
@ -41,7 +43,6 @@ AiIndexer::AiIndexer(QObject *parent) : QObject(parent), d(new AiIndexerPrivate)
|
|||
|
||||
AiIndexer::~AiIndexer()
|
||||
{
|
||||
destroySession();
|
||||
d->m_mutex.unlock();
|
||||
if(d) {
|
||||
delete d;
|
||||
|
@ -51,30 +52,34 @@ AiIndexer::~AiIndexer()
|
|||
|
||||
bool AiIndexer::creatSession()
|
||||
{
|
||||
DataManagementResult result = data_management_create_session(&d->m_session, DataManagementType::SYS_SEARCH, getuid());
|
||||
qDebug() << "===creatSession===" <<result;
|
||||
if(result == DataManagementResult::DATA_MANAGEMENT_SUCCESS) {
|
||||
d->m_sessionValid = true;
|
||||
if(!AiIndexerPrivate::m_sessionValid) {
|
||||
DataManagementResult result = data_management_create_session(&AiIndexerPrivate::m_session, DataManagementType::SYS_SEARCH, getuid());
|
||||
qDebug() << "===creatSession===" <<result;
|
||||
if(result == DataManagementResult::DATA_MANAGEMENT_SUCCESS) {
|
||||
AiIndexerPrivate::m_sessionValid = true;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool AiIndexer::destroySession()
|
||||
{
|
||||
d->m_sessionValid = false;
|
||||
return data_management_destroy_session(d->m_session) == DataManagementResult::DATA_MANAGEMENT_SUCCESS;
|
||||
AiIndexerPrivate::m_sessionValid = false;
|
||||
return data_management_destroy_session(AiIndexerPrivate::m_session) == DataManagementResult::DATA_MANAGEMENT_SUCCESS;
|
||||
}
|
||||
|
||||
bool AiIndexer::checkFileSupported(const QString &filePath, QString &result)
|
||||
{
|
||||
if(!d->m_sessionValid) {
|
||||
if(!AiIndexerPrivate::m_sessionValid) {
|
||||
return false;
|
||||
}
|
||||
char *originalResult;
|
||||
if(data_management_check_file_format(d->m_session, filePath.toLocal8Bit().data(), &originalResult) == DataManagementResult::DATA_MANAGEMENT_SUCCESS) {
|
||||
if(data_management_check_file_format(AiIndexerPrivate::m_session, filePath.toLocal8Bit().data(), &originalResult) == DataManagementResult::DATA_MANAGEMENT_SUCCESS) {
|
||||
QJsonObject jo = QJsonDocument::fromJson(QByteArray(originalResult)).object();
|
||||
data_management_free_check_file_format_result(d->m_session, originalResult);
|
||||
data_management_free_check_file_format_result(AiIndexerPrivate::m_session, originalResult);
|
||||
if(jo.value(QStringLiteral("supported")).toBool()) {
|
||||
result = jo.value(QStringLiteral("format")).toString();
|
||||
return true;
|
||||
|
@ -87,23 +92,23 @@ bool AiIndexer::checkFileSupported(const QString &filePath, QString &result)
|
|||
|
||||
bool AiIndexer::addTextFileIndex(const QJsonArray &object)
|
||||
{
|
||||
if(!d->m_sessionValid) {
|
||||
if(!AiIndexerPrivate::m_sessionValid) {
|
||||
return false;
|
||||
}
|
||||
return data_management_add_text_files(d->m_session, QJsonDocument(object).toJson().data()) == DataManagementResult::DATA_MANAGEMENT_SUCCESS;
|
||||
return data_management_add_text_files(AiIndexerPrivate::m_session, QJsonDocument(object).toJson().data()) == DataManagementResult::DATA_MANAGEMENT_SUCCESS;
|
||||
}
|
||||
|
||||
bool AiIndexer::addImageFileIndex(const QJsonArray &object)
|
||||
{
|
||||
if(!d->m_sessionValid) {
|
||||
if(!AiIndexerPrivate::m_sessionValid) {
|
||||
return false;
|
||||
}
|
||||
return data_management_add_image_files(d->m_session, QJsonDocument(object).toJson().data()) == DataManagementResult::DATA_MANAGEMENT_SUCCESS;
|
||||
return data_management_add_image_files(AiIndexerPrivate::m_session, QJsonDocument(object).toJson().data()) == DataManagementResult::DATA_MANAGEMENT_SUCCESS;
|
||||
}
|
||||
|
||||
bool AiIndexer::deleteFileIndex(const QStringList &files)
|
||||
{
|
||||
if(!d->m_sessionValid) {
|
||||
if(!AiIndexerPrivate::m_sessionValid) {
|
||||
return false;
|
||||
}
|
||||
QJsonArray tmpArray;
|
||||
|
@ -114,16 +119,16 @@ bool AiIndexer::deleteFileIndex(const QStringList &files)
|
|||
tmpArray.append(oneFile);
|
||||
}
|
||||
|
||||
return data_management_delete_files(d->m_session, QJsonDocument(tmpArray).toJson().data()) == DataManagementResult::DATA_MANAGEMENT_SUCCESS;
|
||||
return data_management_delete_files(AiIndexerPrivate::m_session, QJsonDocument(tmpArray).toJson().data()) == DataManagementResult::DATA_MANAGEMENT_SUCCESS;
|
||||
}
|
||||
|
||||
bool AiIndexer::getAllIndexedFiles(QJsonObject &object)
|
||||
{
|
||||
if(!d->m_sessionValid) {
|
||||
if(!AiIndexerPrivate::m_sessionValid) {
|
||||
return false;
|
||||
}
|
||||
char *originalResult;
|
||||
DataManagementResult result = data_management_get_all_fileinfos(d->m_session, &originalResult);
|
||||
DataManagementResult result = data_management_get_all_fileinfos(AiIndexerPrivate::m_session, &originalResult);
|
||||
if(result == DataManagementResult::DATA_MANAGEMENT_SUCCESS) {
|
||||
QJsonArray array = QJsonDocument::fromJson(QByteArray(originalResult)).array();
|
||||
for(const QJsonValueRef value : array) {
|
||||
|
|
|
@ -230,7 +230,7 @@ void IndexUpdater::updateAiIndex()
|
|||
return;
|
||||
}
|
||||
qDebug() << "| index:" <<file.path();
|
||||
if(indexer.addTextFileIndex(QJsonArray{
|
||||
if((indexer.*creat)(QJsonArray{
|
||||
QJsonObject{
|
||||
{QStringLiteral("filepath"), file.path()},
|
||||
{QStringLiteral("filetype"), type}
|
||||
|
|
Loading…
Reference in New Issue