mirror of
https://github.com/irislib/iris-messenger.git
synced 2024-09-20 01:56:33 +00:00
faster "event seen" check
This commit is contained in:
parent
78d51c1bb3
commit
e94a9963ae
@ -46,6 +46,7 @@ const Events = {
|
||||
DEFAULT_GLOBAL_FILTER,
|
||||
getEventHash,
|
||||
db: events,
|
||||
seen: new Set<string>(),
|
||||
deletedEvents: new Set<string>(),
|
||||
directMessagesByUser: new Map<string, SortedLimitedEventSet>(),
|
||||
latestNotificationByTargetAndKind: new Map<string, string>(),
|
||||
@ -411,7 +412,7 @@ const Events = {
|
||||
},
|
||||
handle(event: Event & { id: string }, force = false, saveToIdb = true): boolean {
|
||||
if (!event) return;
|
||||
if (!force && !!this.db.by('id', event.id)) {
|
||||
if (!force && this.seen.has(event.id)) {
|
||||
return false;
|
||||
}
|
||||
if (!force && !this.acceptEvent(event)) {
|
||||
@ -437,6 +438,8 @@ const Events = {
|
||||
return false;
|
||||
}
|
||||
|
||||
this.seen.add(event.id);
|
||||
|
||||
this.handledMsgsPerSecond++;
|
||||
|
||||
PubSub.subscribedEventIds.delete(event.id);
|
||||
|
@ -23,8 +23,18 @@ let dev: any = {
|
||||
};
|
||||
const relayPool = new RelayPool(Relays.DEFAULT_RELAYS, {
|
||||
useEventCache: false,
|
||||
|
||||
externalGetEventById: (id) => Events.db.by('id', id),
|
||||
externalGetEventById: (id) =>
|
||||
(Events.seen.has(id) && {
|
||||
// make externalGetEventById take booleans instead of events?
|
||||
sig: '',
|
||||
id: '',
|
||||
kind: 0,
|
||||
tags: [],
|
||||
content: '',
|
||||
created_at: 0,
|
||||
pubkey: '',
|
||||
}) ||
|
||||
undefined,
|
||||
});
|
||||
localState.get('dev').on((d) => {
|
||||
dev = d;
|
||||
|
@ -307,7 +307,7 @@ const Relays = {
|
||||
},
|
||||
relayInit(url: string, subscribeAll = true) {
|
||||
const relay = relayInit(url, (id) => {
|
||||
const have = !!Events.db.by('id', id);
|
||||
const have = !!Events.seen.has(id);
|
||||
// console.log('have?', have);
|
||||
return have;
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user