correct database new data streaming (#419)

This commit is contained in:
BlowaterNostr 2024-03-17 17:09:41 +08:00 committed by GitHub
parent 9d2901fe39
commit 1bc41d6852
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 7 additions and 4 deletions

View File

@ -102,7 +102,6 @@ Deno.test("Relay Record", async () => {
),
);
await stream.pop();
await stream.pop();
await stream.pop();

View File

@ -214,8 +214,9 @@ export class Database_View
return false;
}
let new_relay_record = false;
if (url) {
await this.recordRelay(event.id, url);
new_relay_record = await this.recordRelay(event.id, url);
}
// parse the event to desired format
@ -233,7 +234,7 @@ export class Database_View
// check if the event exists
const storedEvent = await this.eventsAdapter.get({ id: event.id });
if (storedEvent) { // event exist
if (url) {
if (new_relay_record) {
this.sourceOfChange.put({ event: parsedEvent, relay: url });
}
return false;
@ -281,13 +282,16 @@ export class Database_View
}
private async recordRelay(eventID: string, url: string) {
await this.relayRecorder.setRelayRecord(eventID, url);
const records = this.relayRecords.get(eventID);
if (records) {
const size = records.size;
records.add(url);
return records.size > size;
} else {
this.relayRecords.set(eventID, new Set([url]));
return true;
}
await this.relayRecorder.setRelayRecord(eventID, url);
}
}