fix(search): honor in-memory cache on unchanged setSearch and full view
Repeated setSearch with the same query now marks searchResultsCached when the resolve cache is still valid, and cache hits apply to full view() polls so agentctl and headless sessions do not re-run guild.search every tick. Co-authored-by: Cursor <[email protected]>
This commit is contained in:
@@ -331,6 +331,7 @@ class PearcordPlatform extends EventEmitter {
|
||||
this._searchQuery = ''
|
||||
this._searchScope = 'channel'
|
||||
this._searchIncludeMesh = true
|
||||
this._searchUnchanged = false
|
||||
this._lastSearchMeshMeta = null
|
||||
this._guildSearchIndexes = new Map()
|
||||
this._searchIndexStore = null
|
||||
@@ -1170,6 +1171,21 @@ class PearcordPlatform extends EventEmitter {
|
||||
nextScope === this._searchScope &&
|
||||
(includeMesh === undefined || nextMesh === this._searchIncludeMesh)
|
||||
) {
|
||||
this._searchUnchanged = true
|
||||
const cacheKey = this._searchResolveCacheKeyNow()
|
||||
if (
|
||||
this._cachedSearchResults &&
|
||||
cacheKey === this._searchResolveCacheKey &&
|
||||
this._searchCacheGuildId === (this.guild?.guild?.id || '')
|
||||
) {
|
||||
this._lastSearchFromCache = true
|
||||
if (this._lastSearchMeshMeta) {
|
||||
this._lastSearchMeshMeta = {
|
||||
...this._lastSearchMeshMeta,
|
||||
searchCached: true
|
||||
}
|
||||
}
|
||||
}
|
||||
return {
|
||||
query: this._searchQuery,
|
||||
scope: this._searchScope,
|
||||
@@ -1177,6 +1193,7 @@ class PearcordPlatform extends EventEmitter {
|
||||
unchanged: true
|
||||
}
|
||||
}
|
||||
this._searchUnchanged = false
|
||||
this._searchQuery = nextQuery
|
||||
this._searchScope = nextScope
|
||||
if (includeMesh !== undefined) this._searchIncludeMesh = nextMesh
|
||||
@@ -1335,7 +1352,7 @@ class PearcordPlatform extends EventEmitter {
|
||||
const light = !!opts.light
|
||||
const cacheKey = this._searchResolveCacheKeyNow()
|
||||
const guildId = this.guild.guild.id
|
||||
if (light && cacheKey === this._searchResolveCacheKey && this._cachedSearchResults) {
|
||||
if (cacheKey === this._searchResolveCacheKey && this._cachedSearchResults) {
|
||||
const channelCacheStale =
|
||||
this._searchScope === 'channel' &&
|
||||
this._cachedSearchResults.some(
|
||||
@@ -10628,6 +10645,7 @@ class PearcordPlatform extends EventEmitter {
|
||||
)
|
||||
: [],
|
||||
searchScope: this._searchScope,
|
||||
searchUnchanged: !!this._searchUnchanged,
|
||||
forumIncludeArchived: this._forumIncludeArchived,
|
||||
searchResults: await this._resolveSearchResults({ light }),
|
||||
searchResultsCached: !!this._lastSearchFromCache,
|
||||
|
||||
Reference in New Issue
Block a user