8#include "idfilenamedb.h"
9#include "enginedebug.h"
13IdFilenameDB::IdFilenameDB(MDB_dbi dbi, MDB_txn* txn)
17 Q_ASSERT(txn !=
nullptr);
21IdFilenameDB::~IdFilenameDB()
25MDB_dbi IdFilenameDB::create(MDB_txn* txn)
28 int rc = mdb_dbi_open(txn,
"idfilename", MDB_CREATE | MDB_INTEGERKEY, &dbi);
30 qCWarning(ENGINE) <<
"IdFilenameDB::create" << mdb_strerror(rc);
37MDB_dbi IdFilenameDB::open(MDB_txn* txn)
40 int rc = mdb_dbi_open(txn,
"idfilename", MDB_INTEGERKEY, &dbi);
42 qCWarning(ENGINE) <<
"IdFilenameDB::open" << mdb_strerror(rc);
49void IdFilenameDB::put(quint64 docId,
const FilePath& path)
55 key.mv_size =
sizeof(quint64);
56 key.mv_data =
static_cast<void*
>(&docId);
59 memcpy(data.data(), &
path.parentId, 8);
63 val.mv_size = data.size();
64 val.mv_data =
static_cast<void*
>(data.data());
66 int rc = mdb_put(m_txn, m_dbi, &key, &val, 0);
68 qCWarning(ENGINE) <<
"IdFilenameDB::put" << mdb_strerror(rc);
72IdFilenameDB::FilePath IdFilenameDB::get(quint64 docId)
75 if (get(docId, path)) {
81bool IdFilenameDB::get(quint64 docId, FilePath& path)
86 key.mv_size =
sizeof(quint64);
87 key.mv_data =
static_cast<void*
>(&docId);
89 MDB_val val{0,
nullptr};
90 int rc = mdb_get(m_txn, m_dbi, &key, &val);
92 if (rc != MDB_NOTFOUND) {
93 qCDebug(ENGINE) <<
"IdfilenameDB::get" << docId << mdb_strerror(rc);
97 if (val.mv_size < 8) {
102 memcpy(&
path.parentId, val.mv_data, 8);
103 memcpy(
path.name.
data(),
static_cast<const char*
>(val.mv_data) + 8,
path.name.
size());
108bool IdFilenameDB::contains(quint64 docId)
113 key.mv_size =
sizeof(quint64);
114 key.mv_data =
static_cast<void*
>(&docId);
116 MDB_val val{0,
nullptr};
117 int rc = mdb_get(m_txn, m_dbi, &key, &val);
119 if (rc != MDB_NOTFOUND) {
120 qCDebug(ENGINE) <<
"IdfilenameDB::contains" << docId << mdb_strerror(rc);
127void IdFilenameDB::del(quint64 docId)
132 key.mv_size =
sizeof(quint64);
133 key.mv_data =
static_cast<void*
>(&docId);
135 int rc = mdb_del(m_txn, m_dbi, &key,
nullptr);
136 if (rc != 0 && rc != MDB_NOTFOUND) {
137 qCDebug(ENGINE) <<
"IdFilenameDB::del" << mdb_strerror(rc);
144 mdb_cursor_open(m_txn, m_dbi, &cursor);
146 MDB_val key = {0,
nullptr};
151 int rc = mdb_cursor_get(cursor, &key, &val, MDB_NEXT);
153 qCDebug(ENGINE) <<
"IdFilenameDB::toTestMap" << mdb_strerror(rc);
157 const quint64
id = *(
static_cast<quint64*
>(key.mv_data));
160 path.parentId =
static_cast<quint64*
>(val.mv_data)[0];
161 path.name =
QByteArray(
static_cast<char*
>(val.mv_data) + 8, val.mv_size - 8);
163 map.insert(
id, path);
166 mdb_cursor_close(cursor);
Implements storage for docIds without any associated data Instantiated for:
QString path(const QString &relativePath)
bool isEmpty() const const
void resize(qsizetype newSize, QChar fillChar)
qsizetype size() const const
QFuture< void > map(Iterator begin, Iterator end, MapFunctor &&function)