diff --git a/src/commands/git/search.ts b/src/commands/git/search.ts index 6f6a731..b0f3f0b 100644 --- a/src/commands/git/search.ts +++ b/src/commands/git/search.ts @@ -2,7 +2,7 @@ /* eslint-disable no-loop-func */ import { QuickInputButton } from 'vscode'; import { Container } from '../../container'; -import { GitLogCommit, GitService, Repository } from '../../git/gitService'; +import { GitLog, GitLogCommit, GitService, Repository } from '../../git/gitService'; import { GlyphChars } from '../../constants'; import { QuickCommandBase, StepAsyncGenerator, StepSelection, StepState } from '../quickCommand'; import { RepositoryQuickPickItem } from '../../quickpicks'; @@ -77,6 +77,8 @@ export class SearchGitCommand extends QuickCommandBase { const state: StepState = this._initialState === undefined ? { counter: 0 } : this._initialState; let oneRepo = false; let pickedCommit: GitLogCommit | undefined; + let resultsKey: string | undefined; + let resultsPromise: Promise | undefined; const cfg = Container.config.gitCommands.search; if (state.matchAll === undefined) { @@ -368,22 +370,23 @@ export class SearchGitCommand extends QuickCommandBase { state.search = selection[0].item.trim(); } - const resultsPromise = Container.git.getLogForSearch(state.repo.path, { + const search = { pattern: state.search, matchAll: state.matchAll, matchCase: state.matchCase, matchRegex: state.matchRegex - }); + }; + const searchKey = JSON.stringify(search); + + if (resultsPromise === undefined || resultsKey !== searchKey) { + resultsPromise = Container.git.getLogForSearch(state.repo.path, search); + resultsKey = searchKey; + } if (state.showInView) { void Container.searchView.search( state.repo.path, - { - pattern: state.search, - matchAll: state.matchAll, - matchCase: state.matchCase, - matchRegex: state.matchRegex - }, + search, { label: { label: `commits matching: ${state.search}` } }, @@ -434,12 +437,7 @@ export class SearchGitCommand extends QuickCommandBase { void Container.searchView.search( state.repo!.path, - { - pattern: state.search!, - matchAll: state.matchAll, - matchCase: state.matchCase, - matchRegex: state.matchRegex - }, + search, { label: { label: `commits matching: ${state.search}` } }, diff --git a/src/views/searchView.ts b/src/views/searchView.ts index 2744e35..64a2e3d 100644 --- a/src/views/searchView.ts +++ b/src/views/searchView.ts @@ -217,15 +217,15 @@ export class SearchView extends ViewBase { }; } ): (maxCount: number | undefined) => Promise { + let useCacheOnce = true; + return async (maxCount: number | undefined) => { - const res = await results; + let log = await results; - let log; - if (res !== undefined) { - log = await (res.query === undefined - ? (maxCount: number | undefined) => Promise.resolve(res) - : res.query)(maxCount); + if (!useCacheOnce && log !== undefined && log.query !== undefined) { + log = await log.query(maxCount); } + useCacheOnce = false; const label = this.getSearchLabel(options.label, log); return {