feat: build username index on startup
This commit is contained in:
parent
73b38d37e7
commit
c4b9b397a6
2 changed files with 31 additions and 1 deletions
|
|
@ -86,10 +86,15 @@ class ClientService extends EventTarget {
|
||||||
public static getInstance(): ClientService {
|
public static getInstance(): ClientService {
|
||||||
if (!ClientService.instance) {
|
if (!ClientService.instance) {
|
||||||
ClientService.instance = new ClientService()
|
ClientService.instance = new ClientService()
|
||||||
|
ClientService.instance.init()
|
||||||
}
|
}
|
||||||
return ClientService.instance
|
return ClientService.instance
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async init() {
|
||||||
|
await indexedDb.iterateProfileEvents((profileEvent) => this.addUsernameToIndex(profileEvent))
|
||||||
|
}
|
||||||
|
|
||||||
listConnectionStatus() {
|
listConnectionStatus() {
|
||||||
return this.pool.listConnectionStatus()
|
return this.pool.listConnectionStatus()
|
||||||
}
|
}
|
||||||
|
|
@ -851,5 +856,4 @@ class ClientService extends EventTarget {
|
||||||
}
|
}
|
||||||
|
|
||||||
const instance = ClientService.getInstance()
|
const instance = ClientService.getInstance()
|
||||||
|
|
||||||
export default instance
|
export default instance
|
||||||
|
|
|
||||||
|
|
@ -209,6 +209,32 @@ class IndexedDbService {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async iterateProfileEvents(callback: (event: Event) => Promise<void>): Promise<void> {
|
||||||
|
await this.initPromise
|
||||||
|
if (!this.db) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
return new Promise<void>((resolve, reject) => {
|
||||||
|
const transaction = this.db!.transaction(StoreNames.PROFILE_EVENTS, 'readwrite')
|
||||||
|
const store = transaction.objectStore(StoreNames.PROFILE_EVENTS)
|
||||||
|
const request = store.openCursor()
|
||||||
|
request.onsuccess = (event) => {
|
||||||
|
const cursor = (event.target as IDBRequest).result
|
||||||
|
if (cursor) {
|
||||||
|
callback((cursor.value as TValue<Event>).value)
|
||||||
|
cursor.continue()
|
||||||
|
} else {
|
||||||
|
resolve()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
request.onerror = (event) => {
|
||||||
|
reject(event)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
private getStoreNameByKind(kind: number): string | undefined {
|
private getStoreNameByKind(kind: number): string | undefined {
|
||||||
switch (kind) {
|
switch (kind) {
|
||||||
case kinds.Metadata:
|
case kinds.Metadata:
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue