Skip to content

Commit

Permalink
Fix store.load
Browse files Browse the repository at this point in the history
  • Loading branch information
Lucas Leblow committed May 9, 2024
1 parent c98b93e commit 6a0a5a8
Show file tree
Hide file tree
Showing 5 changed files with 6 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,6 @@ export class CertificatesRequestsStore extends EventEmitter {
this.loadedCertificateRequests()
})

// // @ts-ignore
// await this.store.load({ fetchEntryTimeout: 15000 })

this.logger('Initialized')
}

Expand Down Expand Up @@ -93,8 +90,6 @@ export class CertificatesRequestsStore extends EventEmitter {

public async getCsrs() {
const filteredCsrsMap: Map<string, string> = new Map()
// @ts-expect-error - OrbitDB's type declaration of `load` lacks 'options'
await this.store.load({ fetchEntryTimeout: 15000 })
const allEntries = this.store
.iterator({ limit: -1 })
.collect()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ export class CertificatesStore extends EventEmitter {
write: ['*'],
},
})
await this.store.load()

this.store.events.on('ready', async () => {
this.logger('Loaded certificates to memory')
Expand All @@ -59,8 +58,7 @@ export class CertificatesStore extends EventEmitter {
await this.loadedCertificates()
})

// // @ts-expect-error - OrbitDB's type declaration of `load` lacks 'options'
// await this.store.load({ fetchEntryTimeout: 15000 })
await this.store.load()

this.logger('Initialized')
}
Expand Down Expand Up @@ -156,8 +154,6 @@ export class CertificatesStore extends EventEmitter {
return []
}

// @ts-expect-error - OrbitDB's type declaration of `load` lacks 'options'
await this.store.load({ fetchEntryTimeout: 15000 })
const allCertificates = this.store
.iterator({ limit: -1 })
.collect()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,17 +67,13 @@ export class CommunityMetadataStore extends EventEmitter {

this.store.events.on('replicated', async () => {
logger('Replicated community metadata')
// @ts-expect-error - OrbitDB's type declaration of `load` lacks 'options'
// TODO: Is this necessary here?
await this.store.load({ fetchEntryTimeout: 15000 })
const meta = this.getCommunityMetadata()
if (meta) {
this.emit(StorageEvents.COMMUNITY_METADATA_STORED, meta)
}
})

// @ts-expect-error - OrbitDB's type declaration of `load` lacks 'options'
await this.store.load({ fetchEntryTimeout: 15000 })
await this.store.load()
const meta = this.getCommunityMetadata()
if (meta) {
this.emit(StorageEvents.COMMUNITY_METADATA_STORED, meta)
Expand Down
23 changes: 3 additions & 20 deletions packages/backend/src/nest/storage/storage.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -354,8 +354,6 @@ export class StorageService extends EventEmitter {

public async loadAllChannels() {
this.logger('Getting all channels')
// @ts-expect-error - OrbitDB's type declaration of `load` lacks 'options'
await this.channels.load({ fetchEntryTimeout: 2000 })
this.emit(StorageEvents.CHANNELS_STORED, {
channels: this.channels.all as unknown as { [key: string]: PublicChannel },
})
Expand All @@ -378,8 +376,6 @@ export class StorageService extends EventEmitter {
this.channels.events.on('replicated', async () => {
this.logger('REPLICATED: Channels')
this.emit(SocketActionTypes.CONNECTION_PROCESS_INFO, ConnectionProcessInfo.CHANNELS_STORED)
// @ts-expect-error - OrbitDB's type declaration of `load` lacks 'options'
await this.channels.load({ fetchEntryTimeout: 2000 })

const channels = Object.values(this.channels.all)

Expand All @@ -400,8 +396,7 @@ export class StorageService extends EventEmitter {
})
})

// @ts-expect-error - OrbitDB's type declaration of `load` lacks 'options'
await this.channels.load({ fetchEntryTimeout: 1000 })
await this.channels.load()
this.logger('Channels count:', Object.keys(this.channels.all).length)
this.logger('Channels names:', Object.keys(this.channels.all))
Object.values(this.channels.all).forEach(async (channel: PublicChannel) => {
Expand Down Expand Up @@ -546,6 +541,7 @@ export class StorageService extends EventEmitter {
}
})

// FIXME: load is called twice for channel stores
await db.load()
repo.eventsAttached = true
}
Expand Down Expand Up @@ -603,8 +599,7 @@ export class StorageService extends EventEmitter {

this.publicChannelsRepos.set(channelId, { db, eventsAttached: false })
this.logger(`Set ${channelId} to local channels`)
// @ts-expect-error - OrbitDB's type declaration of `load` lacks 'options'
await db.load({ fetchEntryTimeout: 2000 })
await db.load()
this.logger(`Created channel ${channelId}`)
await this.subscribeToPubSub([StorageService.dbAddress(db.address)])

Expand All @@ -614,8 +609,6 @@ export class StorageService extends EventEmitter {
public async deleteChannel(payload: { channelId: string; ownerPeerId: string }) {
console.log('deleting channel storage', payload)
const { channelId, ownerPeerId } = payload
// @ts-expect-error - OrbitDB's type declaration of `load` lacks 'options'
await this.channels.load({ fetchEntryTimeout: 15000 })
const channel = this.channels.get(channelId)
if (!this.peerId) {
this.logger('deleteChannel - peerId is null')
Expand All @@ -638,18 +631,8 @@ export class StorageService extends EventEmitter {
eventsAttached: false,
}
}
await repo.db.load()
// const allEntries = this.getAllEventLogRawEntries(repo.db)
await repo.db.close()
await repo.db.drop()
// const hashes = allEntries.map(e => CID.parse(e.hash))
// const files = allEntries
// .map(e => {
// return e.payload.value.media
// })
// .filter(isDefined)
// await this.deleteChannelFiles(files)
// await this.deleteChannelMessages(hashes)
this.publicChannelsRepos.delete(channelId)
return { channelId: payload.channelId }
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,7 @@ export class UserProfileStore extends EventEmitter {
})
})

// @ts-expect-error - OrbitDB's type declaration of `load` lacks 'options'
await this.store.load({ fetchEntryTimeout: 15000 })
await this.store.load()
}

public getAddress() {
Expand Down

0 comments on commit 6a0a5a8

Please sign in to comment.