mirror of https://codeberg.org/pzp/pzp-db.git
shuffle some things around
This commit is contained in:
parent
7e90efd48d
commit
4f8d2f1355
|
@ -147,6 +147,19 @@ exports.init = function initDB(peer, config) {
|
|||
return encryptionFormat
|
||||
}
|
||||
|
||||
function populateTangles(tangleIds) {
|
||||
const tangles = {}
|
||||
for (const tangleId of tangleIds) {
|
||||
tangles[tangleId] ??= new Tangle(tangleId, records())
|
||||
}
|
||||
return tangles
|
||||
}
|
||||
|
||||
function loaded(cb) {
|
||||
if (cb === void 0) return promisify(loaded)()
|
||||
scannedLog.onReady(cb)
|
||||
}
|
||||
|
||||
function add(msg, tangleRootHash, cb) {
|
||||
// TODO: optimize this. This may be slow if you're adding many msgs in a
|
||||
// row, because it creates a new Map() each time.
|
||||
|
@ -168,21 +181,6 @@ exports.init = function initDB(peer, config) {
|
|||
}
|
||||
}
|
||||
|
||||
function getFeedRoot(findWho, findType) {
|
||||
for (const rec of records()) {
|
||||
if (FeedV1.isFeedRoot(rec.msg, findWho, findType)) return rec.hash
|
||||
}
|
||||
return null
|
||||
}
|
||||
|
||||
function populateTangles(tangleIds) {
|
||||
const tangles = {}
|
||||
for (const tangleId of tangleIds) {
|
||||
tangles[tangleId] ??= new Tangle(tangleId, records())
|
||||
}
|
||||
return tangles
|
||||
}
|
||||
|
||||
function create(opts, cb) {
|
||||
const keys = opts.keys ?? config.keys
|
||||
|
||||
|
@ -251,6 +249,28 @@ exports.init = function initDB(peer, config) {
|
|||
})
|
||||
}
|
||||
|
||||
function getFeedRoot(findWho, findType) {
|
||||
for (const rec of records()) {
|
||||
if (FeedV1.isFeedRoot(rec.msg, findWho, findType)) return rec.hash
|
||||
}
|
||||
return null
|
||||
}
|
||||
|
||||
function getRecord(msgId) {
|
||||
const isUri = msgId.startsWith('ppppp:')
|
||||
for (let i = 0; i < recs.length; i++) {
|
||||
const rec = recs[i]
|
||||
if (!rec) continue
|
||||
if (isUri && msgId.endsWith(rec.hash)) return rec
|
||||
else if (!isUri && rec.hash === msgId) return rec
|
||||
}
|
||||
return null
|
||||
}
|
||||
|
||||
function get(msgId) {
|
||||
return getRecord(msgId)?.msg
|
||||
}
|
||||
|
||||
function del(msgId, cb) {
|
||||
const rec = getRecord(msgId)
|
||||
const { offset, size, seq } = rec.misc
|
||||
|
@ -274,39 +294,19 @@ exports.init = function initDB(peer, config) {
|
|||
}
|
||||
}
|
||||
|
||||
function getRecord(msgId) {
|
||||
const isUri = msgId.startsWith('ppppp:')
|
||||
for (let i = 0; i < recs.length; i++) {
|
||||
const rec = recs[i]
|
||||
if (!rec) continue
|
||||
if (isUri && msgId.endsWith(rec.hash)) return rec
|
||||
else if (!isUri && rec.hash === msgId) return rec
|
||||
}
|
||||
return null
|
||||
}
|
||||
|
||||
function get(msgId) {
|
||||
return getRecord(msgId)?.msg
|
||||
}
|
||||
|
||||
function loaded(cb) {
|
||||
if (cb === void 0) return promisify(loaded)()
|
||||
scannedLog.onReady(cb)
|
||||
}
|
||||
|
||||
return {
|
||||
// public
|
||||
installEncryptionFormat,
|
||||
loaded,
|
||||
add,
|
||||
create,
|
||||
getFeedRoot,
|
||||
getRecord,
|
||||
get,
|
||||
del,
|
||||
onRecordAdded,
|
||||
msgs,
|
||||
records,
|
||||
getRecord,
|
||||
get,
|
||||
getFeedRoot,
|
||||
|
||||
// internal
|
||||
findEncryptionFormatFor,
|
||||
|
|
Loading…
Reference in New Issue