Baloo

firstrunindexer.cpp
1/*
2 SPDX-FileCopyrightText: 2015 Vishesh Handa <vhanda@kde.org>
3
4 SPDX-License-Identifier: LGPL-2.1-or-later
5*/
6
7#include "firstrunindexer.h"
8#include "basicindexingjob.h"
9#include "fileindexerconfig.h"
10#include "filtereddiriterator.h"
11
12#include "baloodebug.h"
13#include "database.h"
14#include "transaction.h"
15
16#include <QMimeDatabase>
17
18using namespace Baloo;
19
20FirstRunIndexer::FirstRunIndexer(Database* db, FileIndexerConfig* config, const QStringList& folders)
21 : m_db(db)
22 , m_config(config)
23 , m_folders(folders)
24{
25 Q_ASSERT(m_db);
26 Q_ASSERT(m_config);
27 Q_ASSERT(!m_folders.isEmpty());
28}
29
30void FirstRunIndexer::run()
31{
33 BasicIndexingJob::IndexingLevel level = m_config->onlyBasicIndexing() ? BasicIndexingJob::NoLevel
34 : BasicIndexingJob::MarkForContentIndexing;
35
36 for (const QString& folder : std::as_const(m_folders)) {
37 Transaction tr(m_db, Transaction::ReadWrite);
39
40 FilteredDirIterator it(m_config, folder);
41 while (!it.next().isEmpty()) {
43 if (it.fileInfo().isDir()) {
44 mimetype = QStringLiteral("inode/directory");
45 } else {
46 mimetype = mimeDb.mimeTypeForFile(it.filePath(), QMimeDatabase::MatchExtension).name();
47 }
48
49 BasicIndexingJob job(it.filePath(), mimetype, level);
50 if (!job.index()) {
51 continue;
52 }
53
54 // Even though this is the first run, because 2 hard links will resolve to the same id,
55 // we land up crashing (due to the asserts in addDocument).
56 // Hence we are checking before.
57 // FIXME: Silently ignore hard links!
58 //
59 if (tr.hasDocument(job.document().id())) {
60 continue;
61 }
62 tr.addDocument(job.document());
63
65 if (transactionDocumentCount > 20000) {
66 qCDebug(BALOO) << "Commit";
67 tr.commit();
68 tr.reset(Transaction::ReadWrite);
70 }
71 }
72
73 // FIXME: This would consume too much memory. We should make some more commits
74 // based on how much memory we consume
75 tr.commit();
76 }
77
78 Q_EMIT done();
79}
80
81#include "moc_firstrunindexer.cpp"
Active config class which emits signals if the config was changed, for example if the KCM saved the c...
Implements storage for docIds without any associated data Instantiated for:
Definition coding.cpp:11
KIOCORE_EXPORT MimetypeJob * mimetype(const QUrl &url, JobFlags flags=DefaultFlags)
QStringView level(QStringView ifopt)
bool isEmpty() const const
Q_EMITQ_EMIT
QString tr(const char *sourceText, const char *disambiguation, int n)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Tue Mar 26 2024 11:20:16 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.