mirror of
https://github.com/Permissionless-Software-Foundation/psf-memo.git
synced 2026-09-21 16:52:01 -07:00
Indexer: maintain a profileRecency index keyed by address with the newest confirmed qualifying post (top-level 0x6d02 or topic message 0x6d0c). Replies and poll creations do not qualify, and mempool (unconfirmed) posts do not write the index. Setting a profile after posting establishes recency from the address's existing addrPostHeights, excluding replies and polls. DB: GET /profile/recent now orders profiles by their most recent qualifying post (height desc, seen desc, address asc) from profileRecency plus per-page profile lookups, so it no longer scans addrPostHeights or sorts the whole profiles store. Add a profileRecency backfill library and CLI that rebuilds the index from addrPostHeights, posts, postParents, polls, and status, ignoring unconfirmed entries and removing stale records. Add focused unit tests, acceptance fixtures, and regex step handlers. By coder.
42 lines
1.2 KiB
JavaScript
42 lines
1.2 KiB
JavaScript
/*
|
|
In-memory LevelDB double shared by the Memo action-type unit and property
|
|
tests. It supports the get/create/update/delete surface the action handlers
|
|
use and exposes the backing Map as `store` for assertions.
|
|
*/
|
|
|
|
export function makeMemoryDb () {
|
|
const store = new Map()
|
|
return {
|
|
store,
|
|
async get (key) {
|
|
if (!store.has(key)) {
|
|
const err = new Error('not found')
|
|
err.notFound = true
|
|
throw err
|
|
}
|
|
return store.get(key)
|
|
},
|
|
async create (key, value) {
|
|
if (!store.has(key)) store.set(key, value)
|
|
return { success: true }
|
|
},
|
|
async update (key, value) {
|
|
store.set(key, value)
|
|
return { success: true }
|
|
},
|
|
async delete (key) {
|
|
store.delete(key)
|
|
return { success: true }
|
|
},
|
|
async * iterator (opts = {}) {
|
|
let keys = [...store.keys()].sort()
|
|
if (opts.gte !== undefined) keys = keys.filter((key) => key >= opts.gte)
|
|
if (opts.lte !== undefined) keys = keys.filter((key) => key <= opts.lte)
|
|
const limit = opts.limit === undefined ? keys.length : opts.limit
|
|
for (const key of keys.slice(0, limit)) {
|
|
yield [key, store.get(key)]
|
|
}
|
|
}
|
|
}
|
|
}
|