Skip to content

Commit

Permalink
fix: Improve message sending performances (#14800)
Browse files Browse the repository at this point in the history
  • Loading branch information
atomrc committed Mar 10, 2023
1 parent 0a0b3c3 commit 2b0bef9
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions src/script/event/EventService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,12 +127,18 @@ export class EventService {

try {
if (this.storageService.db) {
return await this.storageService.db
.table(StorageSchemata.OBJECT_STORE.EVENTS)
.where('conversation')
.equals(conversationId)
.filter(item => item.data?.replacing_message_id === eventId || item.id === eventId)
.first();
const eventStore = this.storageService.db.table(StorageSchemata.OBJECT_STORE.EVENTS);
// First lookup the event by its direct id (using the index)
const event = eventStore.where('id').equals(eventId).first();
return (
event ||
// If the event was not found, fallback to filtering all the events and check if a `replacing` message is found
eventStore
.where('conversation')
.equals(conversationId)
.filter(item => item.data?.replacing_message_id === eventId || item.id === eventId)
.first()
);
}

const records = await this.storageService.getAll<EventRecord>(StorageSchemata.OBJECT_STORE.EVENTS);
Expand Down

0 comments on commit 2b0bef9

Please sign in to comment.