This commit is contained in:
Raven Scott
2026-06-02 10:29:06 -04:00
parent efca048c2f
commit 73075b6bd6
+86 -5
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,6 +20067,39 @@ class PearcordPlatform extends EventEmitter {
this._reactionListCache?.reactions this._reactionListCache?.reactions
) { ) {
reactions = this._reactionListCache.reactions reactions = this._reactionListCache.reactions
const cachedRows = Array.isArray(this._reactionListCache.rows) ? this._reactionListCache.rows : []
this.log.debug('reaction.list cache hit', {
spanKind: 'reaction.list',
channelId: this.activeChannelId,
guildId: reactionGuildId,
rowCount: cachedRows.length,
messageCount: Object.keys(reactions).length,
activeChannelId: this.activeChannelId,
guildCount: (this.guilds || []).length,
cached: true,
light
})
} else {
const pending = this._reactionListPending
if (pending && pending.cacheKey === cacheKey) {
const rowCount = Array.isArray(pending.rows) ? pending.rows.length : null
this.log.debug('reaction.list pending cache hit', {
spanKind: 'reaction.list',
channelId: this.activeChannelId,
guildId: reactionGuildId,
rowCount,
activeChannelId: this.activeChannelId,
guildCount: (this.guilds || []).length,
cached: true,
pending: true,
light
})
try {
const out = await pending.promise
reactions = out.reactions || {}
} catch {
reactions = {}
}
} else { } else {
const listSpan = this.log.time('reaction.list', { const listSpan = this.log.time('reaction.list', {
spanKind: 'reaction.list', spanKind: 'reaction.list',
@@ -20070,16 +20107,22 @@ class PearcordPlatform extends EventEmitter {
guildId: reactionGuildId, guildId: reactionGuildId,
light light
}) })
try { const loader = (async () => {
const rows = await this.messages.listReactions() const rows = await this.messages.listReactions()
reactions = this._groupReactions(rows) 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._reactionListCacheKey = cacheKey
this._reactionListCache = { rows, reactions } this._reactionListCache = { rows: out.rows, reactions: out.reactions }
this._reactionListPending = null
listSpan.end({ listSpan.end({
spanKind: 'reaction.list', spanKind: 'reaction.list',
channelId: this.activeChannelId, channelId: this.activeChannelId,
guildId: reactionGuildId, guildId: reactionGuildId,
rowCount: rows.length, rowCount: out.rows.length,
messageCount: Object.keys(reactions).length, messageCount: Object.keys(reactions).length,
activeChannelId: this.activeChannelId, activeChannelId: this.activeChannelId,
guildCount: (this.guilds || []).length, guildCount: (this.guilds || []).length,
@@ -20092,11 +20135,13 @@ class PearcordPlatform extends EventEmitter {
guildId: reactionGuildId, guildId: reactionGuildId,
error: err?.message || String(err) error: err?.message || String(err)
}) })
this._reactionListPending = null
listSpan.fail(err) listSpan.fail(err)
reactions = {} reactions = {}
} }
} }
} }
}
this.guilds = await this.listGuilds() this.guilds = await this.listGuilds()
const unread = await this._unreadMap() const unread = await this._unreadMap()
const messageById = {} const messageById = {}
@@ -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
if (pending && pending.cacheKey === pinCacheKey) {
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._pinListCacheKey = pinCacheKey
this._pinListCache = { pins } this._pinListCache = { pins }
} catch {
this._pinListPending = null
pins = []
}
}
} }
} }
const channelSettings = {} const channelSettings = {}