From 40c890b5caf35b8e302e219483eeb64f50407ee4 Mon Sep 17 00:00:00 2001 From: YiFang Xiao Date: Wed, 12 Jul 2023 20:53:16 +0800 Subject: [PATCH 1/2] opt: boost slob fulltext speed MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit and reduce the impact to normal query when create slob fulltext index 🎨 apply clang-format changes --- src/dict/slob.cc | 21 +-------------------- 1 file changed, 1 insertion(+), 20 deletions(-) diff --git a/src/dict/slob.cc b/src/dict/slob.cc index 10fb928a..4946d621 100644 --- a/src/dict/slob.cc +++ b/src/dict/slob.cc @@ -1088,26 +1088,7 @@ quint64 SlobDictionary::getArticlePos( uint32_t articleNumber ) void SlobDictionary::sortArticlesOffsetsForFTS( QVector< uint32_t > & offsets, QAtomicInt & isCancelled ) { - QVector< uint32_t > newOffsets; - newOffsets.reserve( offsets.size() ); - - { - QMutexLocker _( &slobMutex ); - - SlobFile::RefOffsetsVector const & sortedOffsets = sf.getSortedRefOffsets(); - - qint32 entries = sf.getRefsCount(); - for ( qint32 i = 0; i < entries; i++ ) { - if ( Utils::AtomicInt::loadAcquire( isCancelled ) ) - throw exUserAbort(); - if ( offsets.contains( sortedOffsets[ i ].second ) ) - newOffsets.append( sortedOffsets[ i ].second ); - } - } - - offsets.reserve( newOffsets.size() ); - for ( int i = 0; i < newOffsets.size(); i++ ) - offsets[ i ] = newOffsets.at( i ); + //Currently , we use xapian to create the fulltext index. The order of offsets is no important. } void SlobDictionary::makeFTSIndex( QAtomicInt & isCancelled, bool firstIteration ) From 0dc0c015c7602b5a83442e9e517de264958af904 Mon Sep 17 00:00:00 2001 From: YiFang Xiao Date: Wed, 12 Jul 2023 21:11:49 +0800 Subject: [PATCH 2/2] opt: use seperate slob dictionary object to create the fulltext MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 🎨 apply clang-format changes --- src/dict/slob.cc | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/src/dict/slob.cc b/src/dict/slob.cc index 4946d621..b4e13f61 100644 --- a/src/dict/slob.cc +++ b/src/dict/slob.cc @@ -584,6 +584,8 @@ class SlobDictionary: public BtreeIndexing::BtreeDictionary SlobFile sf; QString texCgiPath, texCachePath; + string idxFileName; + public: SlobDictionary( string const & id, string const & indexFile, vector< string > const & dictionaryFiles ); @@ -662,12 +664,11 @@ private: friend class SlobResourceRequest; }; -SlobDictionary::SlobDictionary( string const & id, - string const & indexFile, - vector< string > const & dictionaryFiles ): - BtreeDictionary( id, dictionaryFiles ), - idx( indexFile, "rb" ), - idxHeader( idx.read< IdxHeader >() ) +SlobDictionary::SlobDictionary( string const & id, string const & indexFile, vector< string > const & dictionaryFiles ): + BtreeDictionary( id, dictionaryFiles ), + idxFileName( indexFile ), + idx( indexFile, "rb" ), + idxHeader( idx.read< IdxHeader >() ) { // Open data file @@ -1111,7 +1112,8 @@ void SlobDictionary::makeFTSIndex( QAtomicInt & isCancelled, bool firstIteration try { - FtsHelpers::makeFTSIndex( this, isCancelled ); + const auto slob_dic = std::make_unique< SlobDictionary >( getId(), idxFileName, getDictionaryFilenames() ); + FtsHelpers::makeFTSIndex( slob_dic.get(), isCancelled ); FTS_index_completed.ref(); } catch( std::exception &ex )