mirror of
https://github.com/hoytech/strfry.git
synced 2025-06-19 01:34:57 +00:00
de-duplicate events at final write stage (issue #4)
This commit is contained in:
@ -170,15 +170,19 @@ void writeEvents(lmdb::txn &txn, quadrable::Quadrable &qdb, std::deque<EventToWr
|
|||||||
auto changes = qdb.change();
|
auto changes = qdb.change();
|
||||||
|
|
||||||
std::vector<uint64_t> eventIdsToDelete;
|
std::vector<uint64_t> eventIdsToDelete;
|
||||||
|
std::set<quadrable::Key> seenAlready;
|
||||||
|
|
||||||
for (auto &ev : evs) {
|
for (auto &ev : evs) {
|
||||||
const NostrIndex::Event *flat = flatbuffers::GetRoot<NostrIndex::Event>(ev.flatStr.data());
|
const NostrIndex::Event *flat = flatbuffers::GetRoot<NostrIndex::Event>(ev.flatStr.data());
|
||||||
|
auto quadKey = flatEventToQuadrableKey(flat);
|
||||||
|
|
||||||
if (lookupEventById(txn, sv(flat->id()))) {
|
if (lookupEventById(txn, sv(flat->id())) || seenAlready.contains(quadKey)) {
|
||||||
ev.status = EventWriteStatus::Duplicate;
|
ev.status = EventWriteStatus::Duplicate;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
seenAlready.insert(quadKey);
|
||||||
|
|
||||||
if (env.lookup_Event__deletion(txn, std::string(sv(flat->id())) + std::string(sv(flat->pubkey())))) {
|
if (env.lookup_Event__deletion(txn, std::string(sv(flat->id())) + std::string(sv(flat->pubkey())))) {
|
||||||
ev.status = EventWriteStatus::Deleted;
|
ev.status = EventWriteStatus::Deleted;
|
||||||
continue;
|
continue;
|
||||||
@ -223,7 +227,7 @@ void writeEvents(lmdb::txn &txn, quadrable::Quadrable &qdb, std::deque<EventToWr
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (ev.status == EventWriteStatus::Pending) {
|
if (ev.status == EventWriteStatus::Pending) {
|
||||||
changes.put(flatEventToQuadrableKey(flat), ev.jsonStr, &ev.nodeId);
|
changes.put(quadKey, ev.jsonStr, &ev.nodeId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user