feat(discovery): Phase 492 publish/mesh spans and list cache metadata (v0.8.455)
Add discovery.publish and discovery.mesh timing spans, log cache hits on discovery.list, and use span.fail for discovery.join failures. Co-authored-by: Cursor <[email protected]>
This commit is contained in:
@@ -63,6 +63,8 @@ Expose a single `EventEmitter` API the UI drives over IPC (`apps/pearcord/index.
|
||||
|
||||
**v0.8.443 (Phase 480):** `voice.join` `wasInVoice`/`switchedChannel`; `voice.leave` `hadMedia`; `screen.start` `hasLabel`; `screen.stop` `stopped`. UI voice compositor. Bundle: `npm run test:phase480-voice`. See [VOICE.md](../../docs/VOICE.md).
|
||||
|
||||
**v0.8.455 (Phase 492):** `discovery.publish` on `setGuildDiscoveryListing` (`hasInvite`, `memberCount`); `discovery.mesh` on stats refresh; `discovery.list` logs cache hits (`fromCache: true`); `discovery.join` `span.fail`. UI split discovery compositor + **discovery-errors** dev-log filter. Bundle: `npm run test:phase492-discovery`. See [DISCOVERY.md](../../docs/DISCOVERY.md).
|
||||
|
||||
**v0.8.442 (Phase 479):** `discovery.list` `meshLive`/`filteredCount`; `discovery.join` on `joinPublicDiscovery`; `dm.open` `reusedChannel`; `contacts.accept` `accepted`. UI discovery compositor. Bundle: `npm run test:phase479-discovery`. See [DISCOVERY.md](../../docs/DISCOVERY.md).
|
||||
|
||||
**v0.8.441 (Phase 478):** `notification.markRead` `wasUnread`/`hadMessageId`; `notification.markAll` `unreadBefore`; `notification.open` `hasMessageId`; `inbox.mark-read` `clearedInboxCount`. UI `syncNotificationPanelsDuringGuildLoading` compositor. Bundle: `npm run test:phase478-notifications`. See [NOTIFICATIONS.md](../../docs/NOTIFICATIONS.md), [INBOX.md](../../docs/INBOX.md).
|
||||
|
||||
@@ -7504,21 +7504,40 @@ class PearcordPlatform extends EventEmitter {
|
||||
|
||||
async setGuildDiscoveryListing (guildId, listed) {
|
||||
if (!this.discovery) throw new Error('discovery unavailable')
|
||||
await this.discovery.setGuildPublicListing(guildId, listed)
|
||||
if (listed) {
|
||||
const guild = await this.db.get(COLLECTIONS.GUILDS, { id: guildId })
|
||||
if (!guild) throw new Error('guild not found')
|
||||
const span = this.log.time('discovery.publish', {
|
||||
guildId,
|
||||
listed: !!listed
|
||||
})
|
||||
try {
|
||||
await this.discovery.setGuildPublicListing(guildId, listed)
|
||||
let inviteCode = null
|
||||
let memberCount = 1
|
||||
if (this.guild?.guild?.id === guildId) {
|
||||
const inv = await this.createInvite()
|
||||
inviteCode = inv.shareCode || inv.code
|
||||
memberCount = (await this.guild.listMembers()).length
|
||||
if (listed) {
|
||||
const guild = await this.db.get(COLLECTIONS.GUILDS, { id: guildId })
|
||||
if (!guild) throw new Error('guild not found')
|
||||
if (this.guild?.guild?.id === guildId) {
|
||||
const inv = await this.createInvite()
|
||||
inviteCode = inv.shareCode || inv.code
|
||||
memberCount = (await this.guild.listMembers()).length
|
||||
}
|
||||
await this.discovery.announceGuild(guild, { inviteCode, memberCount })
|
||||
}
|
||||
await this.discovery.announceGuild(guild, { inviteCode, memberCount })
|
||||
this.emit('discovery')
|
||||
span.end({
|
||||
guildId,
|
||||
listed: !!listed,
|
||||
hasInvite: !!inviteCode,
|
||||
memberCount
|
||||
})
|
||||
return { guildId, listed: !!listed }
|
||||
} catch (err) {
|
||||
this.log.error('discovery.publish error', {
|
||||
guildId,
|
||||
error: err?.message || String(err)
|
||||
})
|
||||
span.fail(err)
|
||||
throw err
|
||||
}
|
||||
this.emit('discovery')
|
||||
return { guildId, listed: !!listed }
|
||||
}
|
||||
|
||||
async joinPublicDiscovery (inviteCode) {
|
||||
@@ -7534,7 +7553,7 @@ class PearcordPlatform extends EventEmitter {
|
||||
this.log.error('discovery.join error', {
|
||||
error: err?.message || String(err)
|
||||
})
|
||||
span.end()
|
||||
span.fail(err)
|
||||
throw err
|
||||
}
|
||||
}
|
||||
@@ -12183,6 +12202,20 @@ class PearcordPlatform extends EventEmitter {
|
||||
now - (this._cachedPublicListingsAt || 0) < this._discoveryViewCacheMs
|
||||
if (cacheFresh) {
|
||||
publicListings = this._cachedPublicListings
|
||||
if (!light) {
|
||||
const filter = this._discoveryFilter
|
||||
const filteredCount = this.discovery
|
||||
? this.discovery.filterPublicListings(publicListings, filter).length
|
||||
: publicListings.length
|
||||
const listSpan = this.log.time('discovery.list', {})
|
||||
listSpan.end({
|
||||
count: publicListings.length,
|
||||
filterTag: filter?.tag || null,
|
||||
meshLive: (this.discovery?.peers?.size || 0) > 0,
|
||||
fromCache: true,
|
||||
filteredCount
|
||||
})
|
||||
}
|
||||
} else {
|
||||
try {
|
||||
if (!light) {
|
||||
@@ -12235,7 +12268,13 @@ class PearcordPlatform extends EventEmitter {
|
||||
this._cachedDiscoveryStats = discoveryStats
|
||||
this._cachedDiscoveryStatsAt = now
|
||||
} else {
|
||||
const meshSpan = this.log.time('discovery.mesh', {})
|
||||
discoveryStats = await this.discovery.refreshStats()
|
||||
meshSpan.end({
|
||||
peers: discoveryStats?.peers ?? 0,
|
||||
listings: discoveryStats?.listings ?? publicListings.length,
|
||||
meshLive: !!discoveryStats?.meshLive
|
||||
})
|
||||
this._cachedDiscoveryStats = discoveryStats
|
||||
this._cachedDiscoveryStatsAt = now
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user