1 | /* |
---|---|
2 | This file is part of the KDE Baloo Project |
3 | SPDX-FileCopyrightText: 2015 Pinak Ahuja <pinak.ahuja@gmail.com> |
4 | |
5 | SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL |
6 | */ |
7 | |
8 | #include "unindexedfileindexer.h" |
9 | |
10 | #include "unindexedfileiterator.h" |
11 | #include "transaction.h" |
12 | #include "fileindexerconfig.h" |
13 | #include "baloodebug.h" |
14 | #include "basicindexingjob.h" |
15 | |
16 | using namespace Baloo; |
17 | |
18 | UnindexedFileIndexer::UnindexedFileIndexer(Database* db, const FileIndexerConfig* config) |
19 | : m_db(db) |
20 | , m_config(config) |
21 | { |
22 | } |
23 | |
24 | void UnindexedFileIndexer::run() |
25 | { |
26 | const QStringList includeFolders = m_config->includeFolders(); |
27 | const BasicIndexingJob::IndexingLevel level = m_config->onlyBasicIndexing() ? |
28 | BasicIndexingJob::NoLevel : BasicIndexingJob::MarkForContentIndexing; |
29 | |
30 | for (const QString& includeFolder : includeFolders) { |
31 | Transaction tr(m_db, Transaction::ReadWrite); |
32 | int transactionDocumentCount = 0; |
33 | |
34 | UnIndexedFileIterator it(m_config, &tr, includeFolder); |
35 | while (!it.next().isEmpty()) { |
36 | BasicIndexingJob job(it.filePath(), it.mimetype(), level); |
37 | if (!job.index()) { |
38 | continue; |
39 | } |
40 | |
41 | if (it.mTimeChanged() && level == BasicIndexingJob::MarkForContentIndexing) { |
42 | job.document().setContentIndexing(true); |
43 | } |
44 | |
45 | // We handle modified files by simply updating the mTime and filename in the Db and marking them for ContentIndexing |
46 | const quint64 id = job.document().id(); |
47 | if (tr.hasDocument(id)) { |
48 | DocumentOperations ops = DocumentTime; |
49 | if (it.cTimeChanged()) { |
50 | ops |= XAttrTerms; |
51 | if (QFile::decodeName(localFileName: tr.documentUrl(id)) != it.filePath()) { |
52 | ops |= (FileNameTerms | DocumentUrl); |
53 | } |
54 | } |
55 | tr.replaceDocument(doc: job.document(), operations: ops); |
56 | |
57 | } else { // New file |
58 | tr.addDocument(doc: job.document()); |
59 | } |
60 | |
61 | transactionDocumentCount++; |
62 | if (transactionDocumentCount > 20000) { |
63 | qCDebug(BALOO) << "Commit"; |
64 | tr.commit(); |
65 | tr.reset(type: Transaction::ReadWrite); |
66 | transactionDocumentCount = 0; |
67 | } |
68 | } |
69 | tr.commit(); |
70 | } |
71 | |
72 | Q_EMIT done(); |
73 | } |
74 | |
75 | #include "moc_unindexedfileindexer.cpp" |
76 |