8#include "documenturldb.h"
9#include "postingiterator.h"
10#include "enginedebug.h"
16DocumentUrlDB::DocumentUrlDB(MDB_dbi idTreeDb, MDB_dbi idFilenameDb, MDB_txn* txn)
18 , m_idFilenameDbi(idFilenameDb)
19 , m_idTreeDbi(idTreeDb)
23DocumentUrlDB::~DocumentUrlDB()
27bool DocumentUrlDB::addPath(
const QByteArray& url)
35 IdFilenameDB idFilenameDb(m_idFilenameDbi, m_txn);
38 quint64
id = filePathToId(arr);
41 if (idFilenameDb.contains(
id)) {
54 auto parentId = filePathToId(arr);
58 add(
id, parentId, name);
65bool DocumentUrlDB::put(quint64 docId, quint64 parentId,
const QByteArray& filename)
74 add(docId, parentId, filename);
78void DocumentUrlDB::updateUrl(quint64
id, quint64 newParentId,
const QByteArray& newName)
80 IdFilenameDB idFilenameDb(m_idFilenameDbi, m_txn);
81 IdTreeDB idTreeDb(m_idTreeDbi, m_txn);
84 auto path = idFilenameDb.get(
id);
85 if (
path.parentId != newParentId) {
89 idTreeDb.set(
path.parentId, subDocs);
92 subDocs = idTreeDb.get(newParentId);
94 idTreeDb.set(newParentId, subDocs);
97 if ((newName !=
path.name) || (newParentId !=
path.parentId)) {
98 qCDebug(ENGINE) <<
id <<
"renaming" <<
path.name <<
"to" << newName;
99 path.parentId = newParentId;
101 idFilenameDb.put(
id, path);
105void DocumentUrlDB::del(quint64
id)
108 qCWarning(ENGINE) <<
"del called with invalid docId";
112 IdFilenameDB idFilenameDb(m_idFilenameDbi, m_txn);
113 IdTreeDB idTreeDb(m_idTreeDbi, m_txn);
115 auto path = idFilenameDb.get(
id);
120 idTreeDb.set(
path.parentId, subDocs);
123 qCDebug(ENGINE) <<
id <<
"deleting" <<
path.name;
124 idFilenameDb.del(
id);
127void DocumentUrlDB::add(quint64
id, quint64 parentId,
const QByteArray& name)
133 IdFilenameDB idFilenameDb(m_idFilenameDbi, m_txn);
134 IdTreeDB idTreeDb(m_idTreeDbi, m_txn);
141 idTreeDb.set(parentId, subDocs);
144 IdFilenameDB::FilePath
path;
145 path.parentId = parentId;
148 idFilenameDb.put(
id, path);
151bool DocumentUrlDB::contains(quint64 docId)
const
157 IdFilenameDB idFilenameDb(m_idFilenameDbi, m_txn);
159 return idFilenameDb.contains(docId);
162QByteArray DocumentUrlDB::get(quint64 docId)
const
168 IdFilenameDB idFilenameDb(m_idFilenameDbi, m_txn);
170 IdFilenameDB::FilePath
path;
171 if (!idFilenameDb.get(docId, path)) {
176 quint64
id =
path.parentId;
179 int depth_limit = 512;
182 if (!idFilenameDb.get(
id, path)) {
185 if (!depth_limit--) {
199 IdTreeDB idTreeDb(m_idTreeDbi, m_txn);
200 return idTreeDb.get(docId);
203quint64 DocumentUrlDB::getId(quint64 docId,
const QByteArray& fileName)
const
209 IdFilenameDB idFilenameDb(m_idFilenameDbi, m_txn);
210 IdTreeDB idTreeDb(m_idTreeDbi, m_txn);
213 IdFilenameDB::FilePath
path;
214 for (quint64
id : subFiles) {
215 if (idFilenameDb.get(
id, path) && (
path.name == fileName)) {
225 IdTreeDB idTreeDb(m_idTreeDbi, m_txn);
230 for (
auto it = idTreeMap.
cbegin(); it != idTreeMap.
cend(); it++) {
232 for (quint64
id : it.value()) {
238 for (quint64
id : allIds) {
243 map.insert(
id, path);
Implements storage for docIds without any associated data Instantiated for:
void sortedIdInsert(T &vec, const V &id)
QString name(GameStandardAction id)
QString path(const QString &relativePath)
bool contains(QByteArrayView bv) const const
bool endsWith(QByteArrayView bv) const const
bool isEmpty() const const
qsizetype lastIndexOf(QByteArrayView bv) const const
QByteArray mid(qsizetype pos, qsizetype len) const const
QByteArray & prepend(QByteArrayView ba)
void resize(qsizetype newSize, char c)
bool removeOne(const AT &t)
const_iterator cbegin() const const
const_iterator cend() const const
iterator insert(const T &value)
bool isEmpty() const const
QString & prepend(QChar ch)
QFuture< void > map(Iterator begin, Iterator end, MapFunctor &&function)