8#include "writetransaction.h"
9#include "transaction.h"
12#include "documentdb.h"
13#include "documentiddb.h"
14#include "positiondb.h"
15#include "documenttimedb.h"
16#include "documentdatadb.h"
22void WriteTransaction::addDocument(
const Document& doc)
24 quint64
id = doc.id();
26 DocumentDB documentTermsDB(m_dbis.docTermsDbi, m_txn);
27 DocumentDB documentXattrTermsDB(m_dbis.docXattrTermsDbi, m_txn);
28 DocumentDB documentFileNameTermsDB(m_dbis.docFilenameTermsDbi, m_txn);
29 DocumentTimeDB docTimeDB(m_dbis.docTimeDbi, m_txn);
30 DocumentDataDB docDataDB(m_dbis.docDataDbi, m_txn);
31 DocumentIdDB contentIndexingDB(m_dbis.contentIndexingDbi, m_txn);
32 MTimeDB mtimeDB(m_dbis.mtimeDbi, m_txn);
33 DocumentUrlDB docUrlDB(m_dbis.idTreeDbi, m_dbis.idFilenameDbi, m_txn);
35 Q_ASSERT(!documentTermsDB.contains(
id));
36 Q_ASSERT(!documentXattrTermsDB.contains(
id));
37 Q_ASSERT(!documentFileNameTermsDB.contains(
id));
38 Q_ASSERT(!docTimeDB.contains(
id));
39 Q_ASSERT(!docDataDB.contains(
id));
40 Q_ASSERT(!contentIndexingDB.contains(
id));
41 Q_ASSERT(doc.parentId());
45 int pos = url.lastIndexOf(
'/');
46 auto filename = url.mid(pos + 1);
47 auto parentId = doc.parentId();
50 docUrlDB.addPath(url.left(pos));
55 if (!docUrlDB.put(
id, parentId, filename)) {
61 Q_ASSERT(!docTerms.
empty());
62 documentTermsDB.put(
id, docTerms);
66 documentXattrTermsDB.put(
id, docXattrTerms);
70 if (!docFileNameTerms.
isEmpty()) {
71 documentFileNameTermsDB.put(
id, docFileNameTerms);
74 if (doc.contentIndexing()) {
75 contentIndexingDB.put(doc.id());
78 DocumentTimeDB::TimeInfo info;
79 info.mTime = doc.m_mTime;
80 info.cTime = doc.m_cTime;
82 docTimeDB.put(
id, info);
83 mtimeDB.put(doc.m_mTime,
id);
85 if (!doc.m_data.isEmpty()) {
86 docDataDB.put(
id, doc.m_data);
96 for (
auto it = terms.
cbegin(), end = terms.
cend(); it != end; ++it) {
103 op.data.positions = it.value().positions;
105 m_pendingOperations[term].append(op);
111void WriteTransaction::removeDocument(quint64
id)
113 DocumentDB documentTermsDB(m_dbis.docTermsDbi, m_txn);
114 DocumentDB documentXattrTermsDB(m_dbis.docXattrTermsDbi, m_txn);
115 DocumentDB documentFileNameTermsDB(m_dbis.docFilenameTermsDbi, m_txn);
116 DocumentTimeDB docTimeDB(m_dbis.docTimeDbi, m_txn);
117 DocumentDataDB docDataDB(m_dbis.docDataDbi, m_txn);
118 DocumentIdDB contentIndexingDB(m_dbis.contentIndexingDbi, m_txn);
119 DocumentIdDB failedIndexingDB(m_dbis.failedIdDbi, m_txn);
120 MTimeDB mtimeDB(m_dbis.mtimeDbi, m_txn);
121 DocumentUrlDB docUrlDB(m_dbis.idTreeDbi, m_dbis.idFilenameDbi, m_txn);
123 removeTerms(
id, documentTermsDB.get(
id));
124 removeTerms(
id, documentFileNameTermsDB.get(
id));
125 if (documentXattrTermsDB.contains(
id)) {
126 removeTerms(
id, documentXattrTermsDB.get(
id));
129 documentTermsDB.del(
id);
130 documentXattrTermsDB.del(
id);
131 documentFileNameTermsDB.del(
id);
135 contentIndexingDB.del(
id);
136 failedIndexingDB.del(
id);
138 DocumentTimeDB::TimeInfo info = docTimeDB.get(
id);
140 mtimeDB.del(info.mTime,
id);
152 m_pendingOperations[term].append(op);
156void WriteTransaction::removeRecursively(quint64 parentId)
158 DocumentUrlDB docUrlDB(m_dbis.idTreeDbi, m_dbis.idFilenameDbi, m_txn);
161 for (quint64
id : children) {
163 removeRecursively(
id);
166 removeDocument(parentId);
169bool WriteTransaction::removeRecursively(quint64 parentId,
const std::function<
bool(quint64)> &shouldDelete)
171 DocumentUrlDB docUrlDB(m_dbis.idTreeDbi, m_dbis.idFilenameDbi, m_txn);
173 if (parentId && !shouldDelete(parentId)) {
179 for (quint64
id : children) {
180 isEmpty &= removeRecursively(
id, shouldDelete);
183 if (isEmpty && docUrlDB.getChildren(parentId).isEmpty()) {
184 removeDocument(parentId);
192 DocumentDB documentTermsDB(m_dbis.docTermsDbi, m_txn);
193 DocumentDB documentXattrTermsDB(m_dbis.docXattrTermsDbi, m_txn);
194 DocumentDB documentFileNameTermsDB(m_dbis.docFilenameTermsDbi, m_txn);
195 DocumentTimeDB docTimeDB(m_dbis.docTimeDbi, m_txn);
196 DocumentDataDB docDataDB(m_dbis.docDataDbi, m_txn);
197 DocumentIdDB contentIndexingDB(m_dbis.contentIndexingDbi, m_txn);
198 MTimeDB mtimeDB(m_dbis.mtimeDbi, m_txn);
199 DocumentUrlDB docUrlDB(m_dbis.idTreeDbi, m_dbis.idFilenameDbi, m_txn);
201 const quint64
id = doc.id();
203 if (operations & DocumentTerms) {
204 Q_ASSERT(!doc.m_terms.isEmpty());
208 if (docTerms != prevTerms) {
209 documentTermsDB.put(
id, docTerms);
213 if (operations & XAttrTerms) {
217 if (docXattrTerms != prevTerms) {
218 if (!docXattrTerms.
isEmpty()) {
219 documentXattrTermsDB.put(
id, docXattrTerms);
221 documentXattrTermsDB.del(
id);
226 if (operations & FileNameTerms) {
230 if (docFileNameTerms != prevTerms) {
231 if (!docFileNameTerms.
isEmpty()) {
232 documentFileNameTermsDB.put(
id, docFileNameTerms);
234 documentFileNameTermsDB.del(
id);
239 if (doc.contentIndexing()) {
240 contentIndexingDB.put(doc.id());
243 if (operations & DocumentTime) {
244 DocumentTimeDB::TimeInfo info = docTimeDB.get(
id);
245 if (info.mTime != doc.m_mTime) {
246 mtimeDB.del(info.mTime,
id);
247 mtimeDB.put(doc.m_mTime,
id);
250 info.mTime = doc.m_mTime;
251 info.cTime = doc.m_cTime;
252 docTimeDB.put(
id, info);
255 if (operations & DocumentData) {
256 if (!doc.m_data.isEmpty()) {
257 docDataDB.put(
id, doc.m_data);
263 if (operations & DocumentUrl) {
264 auto url = doc.url();
265 int pos = url.lastIndexOf(
'/');
266 auto newname = url.mid(pos + 1);
267 docUrlDB.updateUrl(doc.id(), doc.parentId(), newname);
280 m_pendingOperations[term].append(op);
283 return addTerms(
id, terms);
286void WriteTransaction::commit()
288 PostingDB postingDB(m_dbis.postingDbi, m_txn);
289 PositionDB positionDB(m_dbis.positionDBi, m_txn);
292 while (iter.hasNext()) {
300 bool fetchedPositionList =
false;
303 for (
const Operation& op : operations) {
304 quint64
id = op.data.docId;
306 if (op.type == AddId) {
309 if (!op.data.positions.isEmpty()) {
310 if (!fetchedPositionList) {
311 positionList = positionDB.get(term);
312 fetchedPositionList =
true;
318 sortedIdRemove(list,
id);
319 if (!fetchedPositionList) {
320 positionList = positionDB.get(term);
321 fetchedPositionList =
true;
323 sortedIdRemove(positionList, PositionInfo(
id));
328 postingDB.put(term, list);
333 if (fetchedPositionList) {
335 positionDB.put(term, positionList);
337 positionDB.del(term);
342 m_pendingOperations.
clear();
Implements storage for a set of s for the given docId Instantiated for:
The MTime DB maps the file mtime to its id.
The PostingDB is the main database that maps -> <id1> <id2> <id2> ... This is used to lookup ids whe...
Implements storage for docIds without any associated data Instantiated for:
void sortedIdInsert(T &vec, const V &id)
KIOCORE_EXPORT QStringList list(const QString &fileClass)
void reserve(qsizetype size)
qsizetype size() const const
void append(QList< T > &&value)
bool isEmpty() const const
void reserve(qsizetype size)
qsizetype size() const const
const_iterator cbegin() const const
const_iterator cend() const const
size_type size() const const