faster content filtering and record urls on new events (#439)

This commit is contained in:
BlowaterNostr 2024-03-26 14:03:03 +08:00 committed by GitHub
parent c5cdfed6da
commit 8604dcd405
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 13 additions and 8 deletions

View File

@ -438,9 +438,14 @@ const handle_update_event = async (chan: PutChannel<true>, args: {
}
continue;
} else if (event.type == "FilterContent") {
const pubkey = PublicKey.FromBech32(event.content.trim());
if (pubkey instanceof PublicKey) {
sync_user_detail_data({ pool, pubkey, database: app.database });
const trimmed = event.content.trim();
if (trimmed.length == 63) {
const pubkey = PublicKey.FromBech32(trimmed);
if (pubkey instanceof PublicKey) {
sync_user_detail_data({ pool, pubkey, database: app.database });
}
} else {
continue;
}
} else {
console.log(event, "is not handled");
@ -665,7 +670,7 @@ async function sync_user_detail_data(
if (msg.res.type == "EOSE") {
break;
} else if (msg.res.type == "EVENT") {
await args.database.addEvent(msg.res.event);
await args.database.addEvent(msg.res.event, msg.url);
}
}
await args.pool.closeSub(args.pubkey.bech32());

View File

@ -17,7 +17,7 @@ export class DexieDatabase extends Dexie implements EventsAdapter, RelayRecorder
constructor() {
super("Events");
this.version(20).stores({
this.version(22).stores({
events: "&id, created_at, kind, tags, pubkey", // indices
relayRecords: "[url+event_id]", // RelayRecord
eventMarks: "&event_id, reason", // RemoveRecords

View File

@ -131,9 +131,6 @@ function filter_messages(msgs: ChatMessage[], filter: FilterContent) {
const noteID = NoteID.FromBech32(filter_string);
const is_note = noteID instanceof NoteID;
msgs = msgs.filter((msg) => {
if (msg.content.toLocaleLowerCase().indexOf(filter_string) != -1) {
return true;
}
if (is_pubkey) {
if (msg.author.hex == pubkey.hex) {
return true;
@ -144,6 +141,9 @@ function filter_messages(msgs: ChatMessage[], filter: FilterContent) {
return true;
}
}
if (msg.content.toLocaleLowerCase().indexOf(filter_string) != -1) {
return true;
}
return false;
});
return msgs;