File indexing completed on 2024-09-08 12:12:31
0001 /* 0002 This file is part of the KDE Baloo project. 0003 SPDX-FileCopyrightText: 2015 Vishesh Handa <vhanda@kde.org> 0004 0005 SPDX-License-Identifier: LGPL-2.1-or-later 0006 */ 0007 0008 #ifndef BALOO_DBSTATE_H 0009 #define BALOO_DBSTATE_H 0010 0011 #include "transaction.h" 0012 #include "postingdb.h" 0013 #include "documentdb.h" 0014 #include "documenturldb.h" 0015 #include "documentiddb.h" 0016 #include "documentdatadb.h" 0017 #include "positiondb.h" 0018 #include "documenttimedb.h" 0019 0020 namespace Baloo { 0021 0022 class DBState { 0023 public: 0024 QMap<QByteArray, PostingList> postingDb; 0025 QMap<QByteArray, QVector<PositionInfo>> positionDb; 0026 0027 QMap<quint64, QVector<QByteArray>> docTermsDb; 0028 QMap<quint64, QVector<QByteArray>> docFileNameTermsDb; 0029 QMap<quint64, QVector<QByteArray>> docXAttrTermsDb; 0030 0031 QMap<quint64, DocumentTimeDB::TimeInfo> docTimeDb; 0032 QMap<quint32, quint64> mtimeDb; 0033 0034 QMap<quint64, QByteArray> docDataDb; 0035 QMap<quint64, QByteArray> docUrlDb; 0036 QVector<quint64> contentIndexingDb; 0037 QVector<quint64> failedIdDb; 0038 0039 bool operator== (const DBState& st) const { 0040 return postingDb == st.postingDb && positionDb == st.positionDb && docTermsDb == st.docTermsDb 0041 && docFileNameTermsDb == st.docFileNameTermsDb && docXAttrTermsDb == st.docXAttrTermsDb 0042 && docTimeDb == st.docTimeDb && mtimeDb == st.mtimeDb && docDataDb == st.docDataDb 0043 && docUrlDb == st.docUrlDb && contentIndexingDb == st.contentIndexingDb 0044 && failedIdDb == st.failedIdDb; 0045 } 0046 0047 static DBState fromTransaction(Transaction* tr); 0048 static bool debugCompare(const DBState& st1, const DBState& st2); 0049 private: 0050 }; 0051 0052 DBState DBState::fromTransaction(Baloo::Transaction* tr) 0053 { 0054 auto dbis = tr->m_dbis; 0055 MDB_txn* txn = tr->m_txn; 0056 0057 PostingDB postingDB(dbis.postingDbi, txn); 0058 PositionDB positionDB(dbis.positionDBi, txn); 0059 DocumentDB documentTermsDB(dbis.docTermsDbi, txn); 0060 DocumentDB documentXattrTermsDB(dbis.docXattrTermsDbi, txn); 0061 DocumentDB documentFileNameTermsDB(dbis.docFilenameTermsDbi, txn); 0062 DocumentTimeDB docTimeDB(dbis.docTimeDbi, txn); 0063 DocumentDataDB docDataDB(dbis.docDataDbi, txn); 0064 DocumentIdDB contentIndexingDB(dbis.contentIndexingDbi, txn); 0065 DocumentIdDB failedIdDb(dbis.failedIdDbi, txn); 0066 MTimeDB mtimeDB(dbis.mtimeDbi, txn); 0067 DocumentUrlDB docUrlDB(dbis.idTreeDbi, dbis.idFilenameDbi, txn); 0068 0069 DBState state; 0070 state.postingDb = postingDB.toTestMap(); 0071 state.positionDb = positionDB.toTestMap(); 0072 state.docTermsDb = documentTermsDB.toTestMap(); 0073 state.docXAttrTermsDb = documentXattrTermsDB.toTestMap(); 0074 state.docFileNameTermsDb = documentFileNameTermsDB.toTestMap(); 0075 state.docTimeDb = docTimeDB.toTestMap(); 0076 state.docDataDb = docDataDB.toTestMap(); 0077 state.mtimeDb = mtimeDB.toTestMap(); 0078 state.contentIndexingDb = contentIndexingDB.toTestVector(); 0079 state.failedIdDb = failedIdDb.toTestVector(); 0080 0081 // FIXME: What about DocumentUrlDB? 0082 // state.docUrlDb = docUrlDB.toTestMap(); 0083 0084 return state; 0085 } 0086 0087 bool DBState::debugCompare(const DBState& st1, const DBState& st2) 0088 { 0089 if (st1.postingDb != st2.postingDb) { 0090 qDebug() << "Posting DB different"; 0091 qDebug() << st1.postingDb; 0092 qDebug() << st2.postingDb; 0093 return false; 0094 } 0095 0096 if (st1.positionDb != st2.positionDb) { 0097 qDebug() << "Position DB different"; 0098 qDebug() << st1.positionDb; 0099 qDebug() << st2.positionDb; 0100 return false; 0101 } 0102 0103 if (st1.docTermsDb != st2.docTermsDb) { 0104 qDebug() << "DocTerms DB different"; 0105 qDebug() << st1.docTermsDb; 0106 qDebug() << st2.docTermsDb; 0107 return false; 0108 } 0109 0110 if (st1.docFileNameTermsDb != st2.docFileNameTermsDb) { 0111 qDebug() << "Doc FileName Terms DB different"; 0112 qDebug() << st1.docFileNameTermsDb; 0113 qDebug() << st2.docFileNameTermsDb; 0114 return false; 0115 } 0116 0117 if (st1.docXAttrTermsDb != st2.docXAttrTermsDb) { 0118 qDebug() << "Doc XAttr Terms DB different"; 0119 qDebug() << st1.docXAttrTermsDb; 0120 qDebug() << st2.docXAttrTermsDb; 0121 return false; 0122 } 0123 0124 if (st1.docTimeDb != st2.docTimeDb) { 0125 qDebug() << "Doc Time DB different"; 0126 qDebug() << st1.docTimeDb; 0127 qDebug() << st2.docTimeDb; 0128 return false; 0129 } 0130 0131 if (st1.mtimeDb != st2.mtimeDb) { 0132 qDebug() << "MTime DB different"; 0133 qDebug() << st1.mtimeDb; 0134 qDebug() << st2.mtimeDb; 0135 return false; 0136 } 0137 0138 return st1 == st2; 0139 } 0140 } // namespace 0141 0142 #endif