This commit is contained in:
Raven Scott
2026-06-02 10:29:06 -04:00
parent efca048c2f
commit 73075b6bd6
+100 -19
View File
@@ -487,9 +487,11 @@ class PearcordPlatform extends EventEmitter {
this._reactionListCacheKey = '' this._reactionListCacheKey = ''
this._reactionListCache = null this._reactionListCache = null
this._reactionListCacheGen = 0 this._reactionListCacheGen = 0
this._reactionListPending = null
this._pinListCacheKey = '' this._pinListCacheKey = ''
this._pinListCache = null this._pinListCache = null
this._pinListCacheGen = 0 this._pinListCacheGen = 0
this._pinListPending = null
this._lastReplicationCompact = null this._lastReplicationCompact = null
this._memberPageBurstTimestamps = [] this._memberPageBurstTimestamps = []
this._guildMeshBoundedByGuild = new Map() this._guildMeshBoundedByGuild = new Map()
@@ -755,12 +757,14 @@ class PearcordPlatform extends EventEmitter {
this._reactionListCacheGen = (this._reactionListCacheGen || 0) + 1 this._reactionListCacheGen = (this._reactionListCacheGen || 0) + 1
this._reactionListCacheKey = '' this._reactionListCacheKey = ''
this._reactionListCache = null this._reactionListCache = null
this._reactionListPending = null
} }
_invalidatePinListCache () { _invalidatePinListCache () {
this._pinListCacheGen = (this._pinListCacheGen || 0) + 1 this._pinListCacheGen = (this._pinListCacheGen || 0) + 1
this._pinListCacheKey = '' this._pinListCacheKey = ''
this._pinListCache = null this._pinListCache = null
this._pinListPending = null
} }
_logMeshChurn (action, extra = {}) { _logMeshChurn (action, extra = {}) {
@@ -20063,37 +20067,78 @@ class PearcordPlatform extends EventEmitter {
this._reactionListCache?.reactions this._reactionListCache?.reactions
) { ) {
reactions = this._reactionListCache.reactions reactions = this._reactionListCache.reactions
} else { const cachedRows = Array.isArray(this._reactionListCache.rows) ? this._reactionListCache.rows : []
const listSpan = this.log.time('reaction.list', { this.log.debug('reaction.list cache hit', {
spanKind: 'reaction.list', spanKind: 'reaction.list',
channelId: this.activeChannelId, channelId: this.activeChannelId,
guildId: reactionGuildId, guildId: reactionGuildId,
rowCount: cachedRows.length,
messageCount: Object.keys(reactions).length,
activeChannelId: this.activeChannelId,
guildCount: (this.guilds || []).length,
cached: true,
light light
}) })
try { } else {
const rows = await this.messages.listReactions() const pending = this._reactionListPending
reactions = this._groupReactions(rows) if (pending && pending.cacheKey === cacheKey) {
this._reactionListCacheKey = cacheKey const rowCount = Array.isArray(pending.rows) ? pending.rows.length : null
this._reactionListCache = { rows, reactions } this.log.debug('reaction.list pending cache hit', {
listSpan.end({
spanKind: 'reaction.list', spanKind: 'reaction.list',
channelId: this.activeChannelId, channelId: this.activeChannelId,
guildId: reactionGuildId, guildId: reactionGuildId,
rowCount: rows.length, rowCount,
messageCount: Object.keys(reactions).length,
activeChannelId: this.activeChannelId, activeChannelId: this.activeChannelId,
guildCount: (this.guilds || []).length, guildCount: (this.guilds || []).length,
cached: false, cached: true,
pending: true,
light light
}) })
} catch (err) { try {
this.log.error('reaction.list error', { const out = await pending.promise
reactions = out.reactions || {}
} catch {
reactions = {}
}
} else {
const listSpan = this.log.time('reaction.list', {
spanKind: 'reaction.list',
channelId: this.activeChannelId, channelId: this.activeChannelId,
guildId: reactionGuildId, guildId: reactionGuildId,
error: err?.message || String(err) light
}) })
listSpan.fail(err) const loader = (async () => {
reactions = {} const rows = await this.messages.listReactions()
return { rows, reactions: this._groupReactions(rows) }
})()
this._reactionListPending = { cacheKey, promise: loader, rows: null }
try {
const out = await loader
reactions = out.reactions
this._reactionListCacheKey = cacheKey
this._reactionListCache = { rows: out.rows, reactions: out.reactions }
this._reactionListPending = null
listSpan.end({
spanKind: 'reaction.list',
channelId: this.activeChannelId,
guildId: reactionGuildId,
rowCount: out.rows.length,
messageCount: Object.keys(reactions).length,
activeChannelId: this.activeChannelId,
guildCount: (this.guilds || []).length,
cached: false,
light
})
} catch (err) {
this.log.error('reaction.list error', {
channelId: this.activeChannelId,
guildId: reactionGuildId,
error: err?.message || String(err)
})
this._reactionListPending = null
listSpan.fail(err)
reactions = {}
}
} }
} }
} }
@@ -20134,10 +20179,46 @@ class PearcordPlatform extends EventEmitter {
const pinCacheKey = `${pinGuildId}:${this.activeChannelId || ''}:${this._pinListCacheGen || 0}` const pinCacheKey = `${pinGuildId}:${this.activeChannelId || ''}:${this._pinListCacheGen || 0}`
if (this._pinListCacheKey === pinCacheKey && Array.isArray(this._pinListCache?.pins)) { if (this._pinListCacheKey === pinCacheKey && Array.isArray(this._pinListCache?.pins)) {
pins = this._pinListCache.pins pins = this._pinListCache.pins
this.log.debug('pin.list cache hit', {
spanKind: 'search.pins',
channelId: this.activeChannelId,
guildId: pinGuildId,
guildCount: (this.guilds || []).length,
pinCount: pins.length,
activeChannelId: this.activeChannelId,
cached: true
})
} else { } else {
pins = await this._channelPins(this.activeChannelId, pinGuildId) const pending = this._pinListPending
this._pinListCacheKey = pinCacheKey if (pending && pending.cacheKey === pinCacheKey) {
this._pinListCache = { pins } this.log.debug('pin.list pending cache hit', {
spanKind: 'search.pins',
channelId: this.activeChannelId,
guildId: pinGuildId,
guildCount: (this.guilds || []).length,
pinCount: Array.isArray(pending.pins) ? pending.pins.length : null,
activeChannelId: this.activeChannelId,
cached: true,
pending: true
})
try {
pins = await pending.promise
} catch {
pins = []
}
} else {
const loader = this._channelPins(this.activeChannelId, pinGuildId)
this._pinListPending = { cacheKey: pinCacheKey, promise: loader, pins: null }
try {
pins = await loader
this._pinListPending = null
this._pinListCacheKey = pinCacheKey
this._pinListCache = { pins }
} catch {
this._pinListPending = null
pins = []
}
}
} }
} }
const channelSettings = {} const channelSettings = {}