Skip to content

Eliminate N+1 queries during search index initialization#368

Open
d-oit wants to merge 2 commits into
mainfrom
perf/eliminate-n-plus-one-search-init-8148724708500007784
Open

Eliminate N+1 queries during search index initialization#368
d-oit wants to merge 2 commits into
mainfrom
perf/eliminate-n-plus-one-search-init-8148724708500007784

Conversation

@d-oit

@d-oit d-oit commented Jul 1, 2026

Copy link
Copy Markdown
Owner

Optimized the initSearch function in src/lib/search/progressive.ts by replacing per-note asynchronous entity name lookups with a synchronous Map lookup. This eliminates N+1 database roundtrips, significantly improving search indexing performance for large knowledge bases.


PR created automatically by Jules for task 8148724708500007784 started by @d-oit

Co-authored-by: d-oit <6849456+d-oit@users.noreply.github.com>
@google-labs-jules

Copy link
Copy Markdown
Contributor

👋 Jules, reporting for duty! I'm here to lend a hand with this pull request.

When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down.

I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job!

For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with @jules. You can find this option in the Pull Request section of your global Jules UI settings. You can always switch back!

New to Jules? Learn more at jules.google/docs.


For security, I will only act on instructions from the user who triggered this task.

@github-actions github-actions Bot added the config label Jul 1, 2026
@deepsource-io

deepsource-io Bot commented Jul 1, 2026

Copy link
Copy Markdown

DeepSource Code Review

We reviewed changes in 3d4c122...9c18602 on this pull request. Below is the summary for the review, and you can see the individual issues we found as inline review comments.

See full review on DeepSource ↗

Important

Some issues found as part of this review are outside of the diff in this pull request and aren't shown in the inline review comments due to GitHub's API limitations. You can see those issues on the DeepSource dashboard.

PR Report Card

Overall Grade   Security  

Reliability  

Complexity  

Hygiene  

Code Review Summary

Analyzer Status Updated (UTC) Details
JavaScript Jul 1, 2026 1:21a.m. Review ↗
Python Jul 1, 2026 1:21a.m. Review ↗
Shell Jul 1, 2026 1:21a.m. Review ↗
SQL Jul 1, 2026 1:21a.m. Review ↗

Important

AI Review is run only on demand for your team. We're only showing results of static analysis review right now. To trigger AI Review, comment @deepsourcebot review on this thread.

const originalIds: string[] = [];

for (const entity of chunk) {
entityNames.set(entity.id!, entity.name);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Forbidden non-null assertion


Using non-null assertions cancels out the benefits of strict null-checking, and introduces the possibility of runtime errors. Avoid non-null assertions unless absolutely necessary. If you still need to use one, write a skipcq comment to explain why it is safe.

for (const entity of chunk) {
entityNames.set(entity.id!, entity.name);
docs.push(buildEntityDoc(entity));
originalIds.push(entity.id!);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Forbidden non-null assertion


Using non-null assertions cancels out the benefits of strict null-checking, and introduces the possibility of runtime errors. Avoid non-null assertions unless absolutely necessary. If you still need to use one, write a skipcq comment to explain why it is safe.

@codacy-production

Copy link
Copy Markdown
Contributor

Up to standards ✅

🟢 Issues 0 issues

Results:
0 new issues

View in Codacy

🟢 Metrics 0 complexity · 0 duplication

Metric Results
Complexity 0
Duplication 0

View in Codacy

NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.

Optimized the `initSearch` function in `src/lib/search/progressive.ts` by replacing per-note asynchronous entity name lookups with a synchronous Map lookup. This eliminates N+1 database roundtrips during search indexing.

Also restored the exclusion of `src/lib/search/__tests__/progressive.test.ts` in `vitest.config.ts` to maintain CI stability.

Co-authored-by: d-oit <6849456+d-oit@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant