opt: indexing dictionary in status bar does not disappear (#1234)

* opt: indexing dictionary name and progress

* [autofix.ci] apply automated fixes

---------

Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
This commit is contained in:
xiaoyifang 2023-10-13 10:43:52 +08:00 committed by GitHub
parent 3a3541cd8a
commit e8a2eadade
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 27 additions and 11 deletions

View file

@ -403,6 +403,9 @@ public:
int getIndexingFtsProgress()
{
if ( haveFTSIndex() ) {
return 100;
}
auto total = getArticleCount();
if ( total == 0 )
return 0;

View file

@ -1067,14 +1067,15 @@ QString DslDictionary::getMainFilename()
void DslDictionary::makeFTSIndex( QAtomicInt & isCancelled, bool firstIteration )
{
if ( !( Dictionary::needToRebuildIndex( getDictionaryFilenames(), ftsIdxName )
|| FtsHelpers::ftsIndexIsOldOrBad( this ) ) )
|| FtsHelpers::ftsIndexIsOldOrBad( this ) ) ) {
FTS_index_completed.ref();
}
if ( haveFTSIndex() )
return;
if ( ensureInitDone().size() )
if ( !ensureInitDone().empty() )
return;
if ( firstIteration && getArticleCount() > FTS::MaxDictionarySizeForFastSearch )

View file

@ -26,13 +26,15 @@ const static std::string finish_mark = std::string( "dehsinif" );
bool ftsIndexIsOldOrBad( BtreeIndexing::BtreeDictionary * dict )
{
try {
Xapian::WritableDatabase db( dict->ftsIndexName() );
Xapian::WritableDatabase const db( dict->ftsIndexName() );
auto docid = db.get_lastdocid();
auto document = db.get_document( docid );
qDebug() << document.get_data().c_str();
string const lastDoc = document.get_data();
bool const notFinished = lastDoc != finish_mark;
qDebug() << dict->ftsIndexName().c_str() << document.get_data().c_str() << notFinished;
//use a special document to mark the end of the index.
return document.get_data() != finish_mark;
return notFinished;
}
catch ( Xapian::Error & e ) {
qWarning() << e.get_description().c_str();
@ -47,7 +49,7 @@ bool ftsIndexIsOldOrBad( BtreeIndexing::BtreeDictionary * dict )
void makeFTSIndex( BtreeIndexing::BtreeDictionary * dict, QAtomicInt & isCancelled )
{
QMutexLocker _( &dict->getFtsMutex() );
QMutexLocker const _( &dict->getFtsMutex() );
//check the index again.
if ( dict->haveFTSIndex() )

View file

@ -40,7 +40,9 @@ void Indexing::run()
sem.acquire();
QFuture< void > const f = QtConcurrent::run( [ this, &sem, &dictionary ]() {
QSemaphoreReleaser const _( sem );
emit sendNowIndexingName( QString::fromUtf8( dictionary->getName().c_str() ) );
const QString & dictionaryName = QString::fromUtf8( dictionary->getName().c_str() );
qDebug() << "[FULLTEXT] make fts for the dictionary:" << dictionaryName;
emit sendNowIndexingName( dictionaryName );
dictionary->makeFTSIndex( isCancelled, false );
} );
synchronizer.addFuture( f );
@ -60,18 +62,26 @@ void Indexing::run()
void Indexing::timeout()
{
//display all the dictionary name in the following loop ,may result only one dictionary name been seen.
//as the interval is so small.
QString indexingDicts;
for ( const auto & dictionary : dictionaries ) {
if ( Utils::AtomicInt::loadAcquire( isCancelled ) )
break;
//Finished, clear the msg.
if ( dictionary->haveFTSIndex() ) {
continue;
}
auto newProgress = dictionary->getIndexingFtsProgress();
if ( newProgress > 0 && newProgress < 100 ) {
emit sendNowIndexingName(
if ( !indexingDicts.isEmpty() )
indexingDicts.append( "," );
indexingDicts.append(
QString( "%1......%%2" ).arg( QString::fromStdString( dictionary->getName() ) ).arg( newProgress ) );
}
}
if ( !indexingDicts.isEmpty() ) {
emit sendNowIndexingName( indexingDicts );
}
}
FtsIndexing::FtsIndexing( std::vector< sptr< Dictionary::Class > > const & dicts ):