Skip to content

Commit

Permalink
don't use flatbuffers for Event index table (make it opaque)
Browse files Browse the repository at this point in the history
  • Loading branch information
hoytech committed Aug 30, 2024
1 parent 7377d52 commit 12a39fd
Show file tree
Hide file tree
Showing 10 changed files with 13 additions and 15 deletions.
6 changes: 2 additions & 4 deletions golpe.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,7 @@ tables:
## Meta-info of nostr events, suitable for indexing
## Primary key is auto-incremented, called "levId" for Local EVent ID
Event:
fields:
- name: packed
type: ubytes
opaque: true

indices:
created_at:
Expand All @@ -48,7 +46,7 @@ tables:
multi: true

indexPrelude: |
PackedEventView packed(v.packed());
PackedEventView packed(v.buf);
created_at = packed.created_at();
uint64_t indexTime = *created_at;
Expand Down
4 changes: 2 additions & 2 deletions src/ActiveMonitors.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ struct ActiveMonitors : NonCopyable {
if (item.latestEventId >= ev.primaryKeyId || item.mon->sub.latestEventId >= ev.primaryKeyId) continue;
item.latestEventId = ev.primaryKeyId;

if (f->doesMatch(PackedEventView(ev.packed()))) {
if (f->doesMatch(PackedEventView(ev.buf))) {
recipients.emplace_back(item.mon->sub.connId, item.mon->sub.subId);
item.mon->sub.latestEventId = ev.primaryKeyId;
continue;
Expand All @@ -113,7 +113,7 @@ struct ActiveMonitors : NonCopyable {
}
};

auto packed = PackedEventView(ev.packed());
auto packed = PackedEventView(ev.buf);

{
auto id = std::string(packed.id());
Expand Down
2 changes: 1 addition & 1 deletion src/DBQuery.h
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ struct DBScan : NonCopyable {
} else {
approxWork += 10;
auto view = env.lookup_Event(txn, levId);
if (view && f.doesMatch(PackedEventView(view->packed()))) doSend = true;
if (view && f.doesMatch(PackedEventView(view->buf))) doSend = true;
}

if (doSend) {
Expand Down
2 changes: 1 addition & 1 deletion src/apps/mesh/cmd_router.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ struct Router {

void outgoingEvent(lmdb::txn &txn, defaultDb::environment::View_Event &ev, std::string &responseStr, tao::json::value &evJson) {
if (dir == "down") return;
if (!filterCompiled.doesMatch(PackedEventView(ev.packed()))) return;
if (!filterCompiled.doesMatch(PackedEventView(ev.buf))) return;

if (responseStr.size() == 0) {
auto evStr = getEventJson(txn, router->decomp, ev.primaryKeyId);
Expand Down
2 changes: 1 addition & 1 deletion src/apps/mesh/cmd_stream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ void cmd_stream(const std::vector<std::string> &subArgs) {
env.foreach_Event(txn, [&](auto &ev){
currEventId = ev.primaryKeyId;

auto id = std::string(PackedEventView(ev.packed()).id());
auto id = std::string(PackedEventView(ev.buf).id());
if (downloadedIds.find(id) != downloadedIds.end()) {
downloadedIds.erase(id);
return true;
Expand Down
2 changes: 1 addition & 1 deletion src/apps/mesh/cmd_sync.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ void cmd_sync(const std::vector<std::string> &subArgs) {

for (auto levId : levIds) {
auto ev = lookupEventByLevId(txn, levId);
PackedEventView packed(ev.packed());
PackedEventView packed(ev.buf);
ne.addItem(packed.created_at(), packed.id().substr(0, ne.idSize));
}

Expand Down
2 changes: 1 addition & 1 deletion src/apps/relay/RelayCron.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ void RelayServer::runCron() {
if (expiration == 1) { // Ephemeral event
auto view = env.lookup_Event(txn, levId);
if (!view) throw herr("missing event from index, corrupt DB?");
uint64_t created = PackedEventView(view->packed()).created_at();
uint64_t created = PackedEventView(view->buf).created_at();

if (created <= ephemeralCutoff) {
numEphemeral++;
Expand Down
2 changes: 1 addition & 1 deletion src/apps/relay/RelayNegentropy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ void RelayServer::runNegentropy(ThreadPool<MsgNegentropy>::Thread &thr) {
for (auto levId : view->levIds) {
try {
auto ev = lookupEventByLevId(txn, levId);
auto packed = PackedEventView(ev.packed());
auto packed = PackedEventView(ev.buf);
view->ne.addItem(packed.created_at(), packed.id().substr(0, view->ne.idSize));
} catch (std::exception &) {
// levId was deleted when query was paused
Expand Down
2 changes: 1 addition & 1 deletion src/apps/relay/RelayReqMonitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ void RelayServer::runReqMonitor(ThreadPool<MsgReqMonitor>::Thread &thr) {
auto connId = msg->sub.connId;

env.foreach_Event(txn, [&](auto &ev){
if (msg->sub.filterGroup.doesMatch(PackedEventView(ev.packed()))) {
if (msg->sub.filterGroup.doesMatch(PackedEventView(ev.buf))) {
sendEvent(connId, msg->sub.subId, getEventJson(txn, decomp, ev.primaryKeyId));
}

Expand Down
4 changes: 2 additions & 2 deletions src/events.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ void writeEvents(lmdb::txn &txn, std::vector<EventToWrite> &evs, uint64_t logLev
auto otherEv = lookupEventByLevId(txn, lmdb::from_sv<uint64_t>(v));

auto thisTimestamp = packed.created_at();
auto otherPacked = PackedEventView(otherEv.packed());
auto otherPacked = PackedEventView(otherEv.buf);
auto otherTimestamp = otherPacked.created_at();

if (otherTimestamp < thisTimestamp ||
Expand All @@ -304,7 +304,7 @@ void writeEvents(lmdb::txn &txn, std::vector<EventToWrite> &evs, uint64_t logLev
packed.foreachTag([&](char tagName, std::string_view tagVal){
if (tagName == 'e') {
auto otherEv = lookupEventById(txn, tagVal);
if (otherEv && PackedEventView(otherEv->packed()).pubkey() == packed.pubkey()) {
if (otherEv && PackedEventView(otherEv->buf).pubkey() == packed.pubkey()) {
if (logLevel >= 1) LI << "Deleting event (kind 5). id=" << to_hex(tagVal);
levIdsToDelete.push_back(otherEv->primaryKeyId);
}
Expand Down

0 comments on commit 12a39fd

Please sign in to comment.