openclaw - ✅(Solved) Fix [Feature]: this.hasIndexedContent() seems to be called too frequently, causing performance issus [1 pull requests, 1 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
openclaw/openclaw#62513Fetched 2026-04-08 03:03:17
View on GitHub
Comments
0
Participants
1
Timeline
3
Reactions
0
Author
Participants
Timeline (top)
cross-referenced ×1labeled ×1referenced ×1
async search(
    query: string,
    opts?: {
      maxResults?: number;
      minScore?: number;
      sessionKey?: string;
    },
  ): Promise<MemorySearchResult[]> {
    const preflight = resolveMemorySearchPreflight({
      query,
      hasIndexedContent: this.hasIndexedContent(),
    });
    if (!preflight.shouldSearch) {
      return [];
    }

in this piece of code, this.hasIndexedContent() will be called on each time we call search(), but this.hasIndexedContent() will query db directly, and may cause performance issues.

Root Cause

async search(
    query: string,
    opts?: {
      maxResults?: number;
      minScore?: number;
      sessionKey?: string;
    },
  ): Promise<MemorySearchResult[]> {
    const preflight = resolveMemorySearchPreflight({
      query,
      hasIndexedContent: this.hasIndexedContent(),
    });
    if (!preflight.shouldSearch) {
      return [];
    }

in this piece of code, this.hasIndexedContent() will be called on each time we call search(), but this.hasIndexedContent() will query db directly, and may cause performance issues.

PR fix notes

PR #62597: perf: cache hasIndexedContent() to avoid redundant SQLite queries

Description (problem / solution / changelog)

Summary

  • Cache the result of hasIndexedContent() which queries SQLite (SELECT 1 FROM chunks LIMIT 1 + FTS table) on every search() call
  • Cache is set to true after chunk inserts, invalidated (reset to null) after deletes and full index resets
  • 3 files changed, 17 insertions — minimal, focused fix

Files changed

FileChange
extensions/memory-core/src/memory/manager-sync-ops.tsAdded hasIndexedContentCached field to base class; invalidate on chunk delete and resetIndex()
extensions/memory-core/src/memory/manager-embedding-ops.tsSet cache to true after chunk insert; invalidate on chunk delete
extensions/memory-core/src/memory/manager.tsUse cached value in hasIndexedContent(), populate on miss

Closes #62513

Test plan

  • manager-search.test.ts passes (3/3)
  • oxlint clean
  • Verify search performance improvement with large memory indices

Changed files

  • extensions/memory-core/src/memory/manager-embedding-ops.ts (modified, +4/-0)
  • extensions/memory-core/src/memory/manager-sync-ops.ts (modified, +8/-0)
  • extensions/memory-core/src/memory/manager.ts (modified, +8/-1)

Code Example

async search(
    query: string,
    opts?: {
      maxResults?: number;
      minScore?: number;
      sessionKey?: string;
    },
  ): Promise<MemorySearchResult[]> {
    const preflight = resolveMemorySearchPreflight({
      query,
      hasIndexedContent: this.hasIndexedContent(),
    });
    if (!preflight.shouldSearch) {
      return [];
    }
RAW_BUFFERClick to expand / collapse

Summary

async search(
    query: string,
    opts?: {
      maxResults?: number;
      minScore?: number;
      sessionKey?: string;
    },
  ): Promise<MemorySearchResult[]> {
    const preflight = resolveMemorySearchPreflight({
      query,
      hasIndexedContent: this.hasIndexedContent(),
    });
    if (!preflight.shouldSearch) {
      return [];
    }

in this piece of code, this.hasIndexedContent() will be called on each time we call search(), but this.hasIndexedContent() will query db directly, and may cause performance issues.

Problem to solve

each time we call this.hasIndexedContent(), the method will access sqlite directly, which can be avoided in most time

Proposed solution

after the first time of we indexed some content in related sqlite tables, we can cache the result by a variable. Then, when we call this.hasIndexedContent() again, db access will be avoided.

Alternatives considered

No response

Impact

only performance loss

Evidence/examples

No response

Additional information

No response

extent analysis

TL;DR

Cache the result of this.hasIndexedContent() to avoid repeated database queries and improve performance.

Guidance

  • Identify the first time content is indexed in the related SQLite tables and cache the result of this.hasIndexedContent() in a variable at that point.
  • Modify the hasIndexedContent() method to return the cached result if it exists, instead of querying the database directly.
  • Consider implementing a mechanism to update the cached result when the indexed content changes.
  • Evaluate the trade-off between the performance gain and the potential for stale data if the cached result is not updated frequently enough.

Example

private hasIndexedContentCached: boolean | null = null;

async search(
  query: string,
  opts?: {
    maxResults?: number;
    minScore?: number;
    sessionKey?: string;
  },
): Promise<MemorySearchResult[]> {
  const preflight = resolveMemorySearchPreflight({
    query,
    hasIndexedContent: this.hasIndexedContent(),
  });
  // ...

private hasIndexedContent(): boolean {
  if (this.hasIndexedContentCached !== null) {
    return this.hasIndexedContentCached;
  }
  const result = /* query db directly */;
  this.hasIndexedContentCached = result;
  return result;
}

Notes

The proposed solution assumes that the result of this.hasIndexedContent() does not change frequently. If the result can change, additional logic will be needed to update the cached result.

Recommendation

Apply workaround: Cache the result of this.hasIndexedContent() to improve performance, as the potential performance gain outweighs the risk of stale data.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING