feat: light view() polls with cached devices list

view(opts) accepts { light: true } to reuse deviceSync.listDevices()
for up to PEARCORD_VIEW_DEVICES_CACHE_MS on hot poll paths.

Co-authored-by: Cursor <[email protected]>
This commit is contained in:
Raven Scott
2026-05-23 04:31:18 -04:00
co-authored by Cursor
parent 00a8869663
commit 8954916895
+20 -4
View File
@@ -9137,7 +9137,8 @@ class PearcordPlatform extends EventEmitter {
return null return null
} }
async view () { async view (opts = {}) {
const light = !!opts.light
const user = this.identity.user const user = this.identity.user
const guild = this.mode === 'guild' ? (this.guild?.guild || null) : null const guild = this.mode === 'guild' ? (this.guild?.guild || null) : null
let channels = [] let channels = []
@@ -9989,13 +9990,28 @@ class PearcordPlatform extends EventEmitter {
guildPresenceSummary: this._guildPresenceSummaryForView(), guildPresenceSummary: this._guildPresenceSummaryForView(),
readOnly: this._readOnly, readOnly: this._readOnly,
contacts: contactsForView, contacts: contactsForView,
devices: this.deviceSync devices: await this._devicesForView(light),
? await this.deviceSync.listDevices()
: [],
deviceId: this.identity?.deviceId || null deviceId: this.identity?.deviceId || null
} }
} }
async _devicesForView (light = false) {
if (!this.deviceSync) return []
const ttlMs = Number(process.env.PEARCORD_VIEW_DEVICES_CACHE_MS) || 30000
const now = Date.now()
if (
light &&
this._cachedViewDevices &&
now - (this._cachedViewDevicesAt || 0) < ttlMs
) {
return this._cachedViewDevices
}
const devices = await this.deviceSync.listDevices()
this._cachedViewDevices = devices
this._cachedViewDevicesAt = now
return devices
}
async _enrichPresenceActivity (activity) { async _enrichPresenceActivity (activity) {
if (!activity?.assets || !this.attachments) return activity if (!activity?.assets || !this.attachments) return activity
const keys = [ const keys = [