refactor(platform): Phase 749 view/search/discovery cache mixins (v0.8.725)
Extract view list cache, guild search cache, and discovery prefs baseline helpers into three prototype mixins (manifest 91 rows, runtime registry 31). Non-breaking: identical cache invalidation, composer focus TTL, and prefs ingest behavior; platform class ~32154 lines (~91 net reduction). Co-authored-by: Cursor <[email protected]>
This commit is contained in:
@@ -54,6 +54,8 @@ Application facade: one `PearcordPlatform` class that wires identity, database,
|
||||
|
||||
**Phase 723 (v0.8.699):** Dedicated slash registry & invoke audit export JSON — `slash-registry-json-mixin.js`, `slash-invoke-audit-json-mixin.js`, spans `slash-registry.json` / `slash-invoke-audit.json`, `getSlashInvokeAuditExportJsonExport`, `clearSlashInvokeAuditExportJsonExports`, deep links `openSlashRegistryJson` / `openSlashInvokeAuditJson`. Bundle: `npm run test:ci-phase723`.
|
||||
|
||||
**Phase 749 (v0.8.725):** `platform-view-list-cache-mixin.js`, `platform-search-cache-mixin.js`, `platform-discovery-prefs-baseline-mixin.js` (91 mixin rows, 31 runtime mixins); reaction/pin cache invalidation, search resolve cache, discovery explore baseline from prefs. Bundle: `npm run test:ci-phase749`.
|
||||
|
||||
**Phase 748 (v0.8.724):** `platform-guild-thread-forum-export-mixin.js`, `platform-discovery-listing-schedule-mixin.js`, `platform-guild-member-sync-schedule-mixin.js` (88 mixin rows, 28 runtime mixins); thread/forum sync export slices, discovery listing push/revoke, member page and attachment pull scheduling. Bundle: `npm run test:ci-phase748`.
|
||||
|
||||
**Phase 747 (v0.8.723):** `platform-guild-sparse-sync-qos-mixin.js`, `platform-guild-contacts-presence-mixin.js`, `platform-voice-mesh-state-mixin.js` (85 mixin rows, 25 runtime mixins); sparse sync QoS, contacts presence reconcile, voice speaking/mute mesh gossip. Bundle: `npm run test:ci-phase747`.
|
||||
|
||||
@@ -0,0 +1,59 @@
|
||||
'use strict'
|
||||
|
||||
const platformDiscoveryPrefsBaselineMixin = {
|
||||
_invalidateDiscoveryListingsCache () {
|
||||
this._cachedPublicListings = null
|
||||
this._cachedPublicListingsAt = 0
|
||||
},
|
||||
|
||||
_ingestDiscoveryExploreBaselineFromPrefs (prefs) {
|
||||
if (!prefs) return
|
||||
if (prefs.discoveryExploreBaseline != null) {
|
||||
const n = Math.max(0, Math.floor(Number(prefs.discoveryExploreBaseline) || 0))
|
||||
this._discoveryExploreBaseline = n
|
||||
}
|
||||
if (prefs.discoveryExploreBaselineAt != null) {
|
||||
this._discoveryExploreBaselineAt = Math.max(
|
||||
0,
|
||||
Math.floor(Number(prefs.discoveryExploreBaselineAt) || 0)
|
||||
)
|
||||
}
|
||||
if (prefs.voiceRosterMutedOnly !== undefined) {
|
||||
this._voiceRosterMutedOnly = !!prefs.voiceRosterMutedOnly
|
||||
}
|
||||
if (prefs.voiceRosterDeafenedOnly !== undefined) {
|
||||
this._voiceRosterDeafenedOnly = !!prefs.voiceRosterDeafenedOnly
|
||||
}
|
||||
if (prefs.threadsPanelFilter) {
|
||||
const allowed = new Set(['active', 'archived', 'all', 'pinned', 'muted', 'pinned-muted', 'locked'])
|
||||
if (allowed.has(prefs.threadsPanelFilter)) {
|
||||
this._threadsPanelFilter = prefs.threadsPanelFilter
|
||||
if (this._threadsPanelFilter === 'archived' || this._threadsPanelFilter === 'all') {
|
||||
this._threadsPanelIncludeArchived = true
|
||||
}
|
||||
}
|
||||
}
|
||||
if (Array.isArray(prefs.voiceRosterExpandedChannelIds)) {
|
||||
this._voiceRosterExpandedChannelIds = new Set(
|
||||
prefs.voiceRosterExpandedChannelIds.map((id) => String(id)).filter(Boolean)
|
||||
)
|
||||
}
|
||||
const df = prefs.discoveryExploreFilter
|
||||
if (df && typeof df === 'object') {
|
||||
if (df.query !== undefined) {
|
||||
this._discoveryFilter.query = String(df.query || '').trim()
|
||||
}
|
||||
if (df.sort === 'members' || df.sort === 'name' || df.sort === 'newest') {
|
||||
this._discoveryFilter.sort = df.sort
|
||||
}
|
||||
if (df.minMembers !== undefined) {
|
||||
this._discoveryFilter.minMembers = Math.max(0, Number(df.minMembers) || 0)
|
||||
}
|
||||
if (df.tag !== undefined) {
|
||||
this._discoveryFilter.tag = String(df.tag || '').trim().toLowerCase()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = { platformDiscoveryPrefsBaselineMixin }
|
||||
@@ -4,7 +4,7 @@
|
||||
* Ordered PearcordPlatform prototype mixin registration (Phase 730).
|
||||
* Preserves assign order from index.js / apply-platform-mixins (Phase 727).
|
||||
*/
|
||||
const PLATFORM_MIXIN_ASSIGNMENT_COUNT = 88
|
||||
const PLATFORM_MIXIN_ASSIGNMENT_COUNT = 91
|
||||
|
||||
const PLATFORM_MIXIN_ASSIGNMENTS = [
|
||||
{ module: './polls-scheduling', export: 'pollSchedulingMixin' },
|
||||
@@ -94,6 +94,9 @@ const PLATFORM_MIXIN_ASSIGNMENTS = [
|
||||
{ module: './platform-guild-thread-forum-export-mixin', export: 'platformGuildThreadForumExportMixin' },
|
||||
{ module: './platform-discovery-listing-schedule-mixin', export: 'platformDiscoveryListingScheduleMixin' },
|
||||
{ module: './platform-guild-member-sync-schedule-mixin', export: 'platformGuildMemberSyncScheduleMixin' },
|
||||
{ module: './platform-view-list-cache-mixin', export: 'platformViewListCacheMixin' },
|
||||
{ module: './platform-search-cache-mixin', export: 'platformSearchCacheMixin' },
|
||||
{ module: './platform-discovery-prefs-baseline-mixin', export: 'platformDiscoveryPrefsBaselineMixin' },
|
||||
{ module: './platform-diagnostics-mixin', export: 'platformDiagnosticsMixin' }
|
||||
]
|
||||
|
||||
|
||||
@@ -919,13 +919,7 @@ class PearcordPlatform extends EventEmitter {
|
||||
|
||||
|
||||
|
||||
_takeComposerFocusAfterHubIngest () {
|
||||
const row = this._composerFocusAfterHubIngest
|
||||
this._composerFocusAfterHubIngest = null
|
||||
if (!row?.channelId || !row?.at) return null
|
||||
if (Date.now() - row.at > 5000) return null
|
||||
return { channelId: row.channelId, at: row.at }
|
||||
}
|
||||
|
||||
|
||||
async _refreshDiscoveryAfterGuildMeshAction (guildId, source) {
|
||||
const gid = guildId || this.guild?.guild?.id
|
||||
@@ -974,19 +968,9 @@ class PearcordPlatform extends EventEmitter {
|
||||
}
|
||||
}
|
||||
|
||||
_invalidateReactionListCache () {
|
||||
this._reactionListCacheGen = (this._reactionListCacheGen || 0) + 1
|
||||
this._reactionListCacheKey = ''
|
||||
this._reactionListCache = null
|
||||
this._reactionListPending = null
|
||||
}
|
||||
|
||||
_invalidatePinListCache () {
|
||||
this._pinListCacheGen = (this._pinListCacheGen || 0) + 1
|
||||
this._pinListCacheKey = ''
|
||||
this._pinListCache = null
|
||||
this._pinListPending = null
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Compare messages, reactions, and pins for the active channel during view build.
|
||||
@@ -3706,25 +3690,9 @@ class PearcordPlatform extends EventEmitter {
|
||||
return { removed: true }
|
||||
}
|
||||
|
||||
_invalidateSearchCache () {
|
||||
this._searchResolveCacheKey = ''
|
||||
this._cachedSearchResults = null
|
||||
this._searchCacheGuildId = ''
|
||||
this._lastSearchFromCache = false
|
||||
}
|
||||
|
||||
_commitSearchCache (cacheKey, results) {
|
||||
this._searchResolveCacheKey = cacheKey
|
||||
this._cachedSearchResults = results
|
||||
this._searchCacheGuildId = this.guild?.guild?.id || ''
|
||||
this._lastSearchFromCache = false
|
||||
if (this._lastSearchMeshMeta) {
|
||||
this._lastSearchMeshMeta = {
|
||||
...this._lastSearchMeshMeta,
|
||||
searchCached: false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
async refreshSearch () {
|
||||
if (!this._searchQuery || this._searchQuery.length < 2 || !this.guild?.guild?.id) {
|
||||
@@ -3893,16 +3861,7 @@ class PearcordPlatform extends EventEmitter {
|
||||
return this.refreshSearch()
|
||||
}
|
||||
|
||||
_searchResolveCacheKeyNow () {
|
||||
return [
|
||||
this.guild?.guild?.id || '',
|
||||
this._searchQuery,
|
||||
this._searchScope,
|
||||
this._searchIncludeMesh ? '1' : '0',
|
||||
this.activeChannelId || '',
|
||||
this._forumIncludeArchived ? '1' : '0'
|
||||
].join('|')
|
||||
}
|
||||
|
||||
|
||||
async _resolveSearchResults (opts = {}) {
|
||||
const q = this._searchQuery
|
||||
@@ -4286,54 +4245,7 @@ class PearcordPlatform extends EventEmitter {
|
||||
|
||||
|
||||
|
||||
_ingestDiscoveryExploreBaselineFromPrefs (prefs) {
|
||||
if (!prefs) return
|
||||
if (prefs.discoveryExploreBaseline != null) {
|
||||
const n = Math.max(0, Math.floor(Number(prefs.discoveryExploreBaseline) || 0))
|
||||
this._discoveryExploreBaseline = n
|
||||
}
|
||||
if (prefs.discoveryExploreBaselineAt != null) {
|
||||
this._discoveryExploreBaselineAt = Math.max(
|
||||
0,
|
||||
Math.floor(Number(prefs.discoveryExploreBaselineAt) || 0)
|
||||
)
|
||||
}
|
||||
if (prefs.voiceRosterMutedOnly !== undefined) {
|
||||
this._voiceRosterMutedOnly = !!prefs.voiceRosterMutedOnly
|
||||
}
|
||||
if (prefs.voiceRosterDeafenedOnly !== undefined) {
|
||||
this._voiceRosterDeafenedOnly = !!prefs.voiceRosterDeafenedOnly
|
||||
}
|
||||
if (prefs.threadsPanelFilter) {
|
||||
const allowed = new Set(['active', 'archived', 'all', 'pinned', 'muted', 'pinned-muted', 'locked'])
|
||||
if (allowed.has(prefs.threadsPanelFilter)) {
|
||||
this._threadsPanelFilter = prefs.threadsPanelFilter
|
||||
if (this._threadsPanelFilter === 'archived' || this._threadsPanelFilter === 'all') {
|
||||
this._threadsPanelIncludeArchived = true
|
||||
}
|
||||
}
|
||||
}
|
||||
if (Array.isArray(prefs.voiceRosterExpandedChannelIds)) {
|
||||
this._voiceRosterExpandedChannelIds = new Set(
|
||||
prefs.voiceRosterExpandedChannelIds.map((id) => String(id)).filter(Boolean)
|
||||
)
|
||||
}
|
||||
const df = prefs.discoveryExploreFilter
|
||||
if (df && typeof df === 'object') {
|
||||
if (df.query !== undefined) {
|
||||
this._discoveryFilter.query = String(df.query || '').trim()
|
||||
}
|
||||
if (df.sort === 'members' || df.sort === 'name' || df.sort === 'newest') {
|
||||
this._discoveryFilter.sort = df.sort
|
||||
}
|
||||
if (df.minMembers !== undefined) {
|
||||
this._discoveryFilter.minMembers = Math.max(0, Number(df.minMembers) || 0)
|
||||
}
|
||||
if (df.tag !== undefined) {
|
||||
this._discoveryFilter.tag = String(df.tag || '').trim().toLowerCase()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
async setVoiceRosterChannelExpanded (channelId, expanded) {
|
||||
const id = String(channelId || '')
|
||||
@@ -4431,10 +4343,7 @@ class PearcordPlatform extends EventEmitter {
|
||||
|
||||
|
||||
|
||||
_invalidateDiscoveryListingsCache () {
|
||||
this._cachedPublicListings = null
|
||||
this._cachedPublicListingsAt = 0
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
'use strict'
|
||||
|
||||
/** Prototype mixins extracted from PearcordPlatform class body (Phases 738–748). */
|
||||
/** Prototype mixins extracted from PearcordPlatform class body (Phases 738–749). */
|
||||
const PLATFORM_RUNTIME_MIXIN_MODULES = [
|
||||
'./platform-hyperswarm-runtime-mixin',
|
||||
'./platform-session-startup-mixin',
|
||||
@@ -29,7 +29,10 @@ const PLATFORM_RUNTIME_MIXIN_MODULES = [
|
||||
'./platform-voice-mesh-state-mixin',
|
||||
'./platform-guild-thread-forum-export-mixin',
|
||||
'./platform-discovery-listing-schedule-mixin',
|
||||
'./platform-guild-member-sync-schedule-mixin'
|
||||
'./platform-guild-member-sync-schedule-mixin',
|
||||
'./platform-view-list-cache-mixin',
|
||||
'./platform-search-cache-mixin',
|
||||
'./platform-discovery-prefs-baseline-mixin'
|
||||
]
|
||||
|
||||
const PLATFORM_RUNTIME_MIXIN_COUNT = PLATFORM_RUNTIME_MIXIN_MODULES.length
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
'use strict'
|
||||
|
||||
const platformSearchCacheMixin = {
|
||||
_invalidateSearchCache () {
|
||||
this._searchResolveCacheKey = ''
|
||||
this._cachedSearchResults = null
|
||||
this._searchCacheGuildId = ''
|
||||
this._lastSearchFromCache = false
|
||||
},
|
||||
|
||||
_commitSearchCache (cacheKey, results) {
|
||||
this._searchResolveCacheKey = cacheKey
|
||||
this._cachedSearchResults = results
|
||||
this._searchCacheGuildId = this.guild?.guild?.id || ''
|
||||
this._lastSearchFromCache = false
|
||||
if (this._lastSearchMeshMeta) {
|
||||
this._lastSearchMeshMeta = {
|
||||
...this._lastSearchMeshMeta,
|
||||
searchCached: false
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
_searchResolveCacheKeyNow () {
|
||||
return [
|
||||
this.guild?.guild?.id || '',
|
||||
this._searchQuery,
|
||||
this._searchScope,
|
||||
this._searchIncludeMesh ? '1' : '0',
|
||||
this.activeChannelId || '',
|
||||
this._forumIncludeArchived ? '1' : '0'
|
||||
].join('|')
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = { platformSearchCacheMixin }
|
||||
@@ -0,0 +1,27 @@
|
||||
'use strict'
|
||||
|
||||
const platformViewListCacheMixin = {
|
||||
_takeComposerFocusAfterHubIngest () {
|
||||
const row = this._composerFocusAfterHubIngest
|
||||
this._composerFocusAfterHubIngest = null
|
||||
if (!row?.channelId || !row?.at) return null
|
||||
if (Date.now() - row.at > 5000) return null
|
||||
return { channelId: row.channelId, at: row.at }
|
||||
},
|
||||
|
||||
_invalidateReactionListCache () {
|
||||
this._reactionListCacheGen = (this._reactionListCacheGen || 0) + 1
|
||||
this._reactionListCacheKey = ''
|
||||
this._reactionListCache = null
|
||||
this._reactionListPending = null
|
||||
},
|
||||
|
||||
_invalidatePinListCache () {
|
||||
this._pinListCacheGen = (this._pinListCacheGen || 0) + 1
|
||||
this._pinListCacheKey = ''
|
||||
this._pinListCache = null
|
||||
this._pinListPending = null
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = { platformViewListCacheMixin }
|
||||
Reference in New Issue
Block a user