8#include "documentiddb.h"
9#include "enginedebug.h"
13DocumentIdDB::DocumentIdDB(MDB_dbi dbi, MDB_txn* txn)
17 Q_ASSERT(txn !=
nullptr);
21DocumentIdDB::~DocumentIdDB()
25MDB_dbi DocumentIdDB::create(
const char* name, MDB_txn* txn)
28 int rc = mdb_dbi_open(txn, name, MDB_CREATE | MDB_INTEGERKEY, &dbi);
30 qCWarning(ENGINE) <<
"DocumentIdDB::create" <<
name << mdb_strerror(rc);
37MDB_dbi DocumentIdDB::open(
const char* name, MDB_txn* txn)
40 int rc = mdb_dbi_open(txn, name, MDB_INTEGERKEY, &dbi);
42 qCWarning(ENGINE) <<
"DocumentIdDB::open" <<
name << mdb_strerror(rc);
49void DocumentIdDB::put(quint64 docId)
54 key.mv_size =
sizeof(quint64);
55 key.mv_data =
static_cast<void*
>(&docId);
59 val.mv_data =
nullptr;
61 int rc = mdb_put(m_txn, m_dbi, &key, &val, 0);
63 qCWarning(ENGINE) <<
"DocumentIdDB::put" << mdb_strerror(rc);
67bool DocumentIdDB::contains(quint64 docId)
72 key.mv_size =
sizeof(quint64);
73 key.mv_data =
static_cast<void*
>(&docId);
75 MDB_val val{0,
nullptr};
76 int rc = mdb_get(m_txn, m_dbi, &key, &val);
78 if (rc != MDB_NOTFOUND) {
79 qCDebug(ENGINE) <<
"DocumentIdDB::contains" << docId << mdb_strerror(rc);
87void DocumentIdDB::del(quint64 docId)
92 key.mv_size =
sizeof(quint64);
93 key.mv_data =
static_cast<void*
>(&docId);
95 int rc = mdb_del(m_txn, m_dbi, &key,
nullptr);
96 if (rc != 0 && rc != MDB_NOTFOUND) {
97 qCDebug(ENGINE) <<
"DocumentIdDB::del" << docId << mdb_strerror(rc);
106 mdb_cursor_open(m_txn, m_dbi, &cursor);
111 for (
int i = 0; i < size; i++) {
112 MDB_val key{0,
nullptr};
113 int rc = mdb_cursor_get(cursor, &key,
nullptr, MDB_NEXT);
115 if (rc != MDB_NOTFOUND) {
116 qCWarning(ENGINE) <<
"DocumentIdDB::fetchItems" << size << mdb_strerror(rc);
121 quint64
id = *(
static_cast<quint64*
>(key.mv_data));
124 mdb_cursor_close(cursor);
129uint DocumentIdDB::size()
132 int rc = mdb_stat(m_txn, m_dbi, &stat);
134 qCDebug(ENGINE) <<
"DocumentIdDB::size" << mdb_strerror(rc);
138 return stat.ms_entries;
144 mdb_cursor_open(m_txn, m_dbi, &cursor);
146 MDB_val key{0,
nullptr};
147 MDB_val val{0,
nullptr};
151 int rc = mdb_cursor_get(cursor, &key, &val, MDB_NEXT);
153 qCDebug(ENGINE) <<
"DocumentTimeDB::toTestMap" << mdb_strerror(rc);
157 const quint64
id = *(
static_cast<quint64*
>(key.mv_data));
161 mdb_cursor_close(cursor);
Implements storage for docIds without any associated data Instantiated for:
KIOCORE_EXPORT StatJob * stat(const QUrl &url, JobFlags flags=DefaultFlags)
QString name(StandardAction id)
void reserve(qsizetype size)