Browse Source

Adds simple caching for search results

main
Eric Amodio 5 years ago
parent
commit
dc51878c7b
2 changed files with 19 additions and 21 deletions
  1. +13
    -15
      src/commands/git/search.ts
  2. +6
    -6
      src/views/searchView.ts

+ 13
- 15
src/commands/git/search.ts View File

@ -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<State> = this._initialState === undefined ? { counter: 0 } : this._initialState;
let oneRepo = false;
let pickedCommit: GitLogCommit | undefined;
let resultsKey: string | undefined;
let resultsPromise: Promise<GitLog | undefined> | 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 class="p">(state.repo .="nx">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}` }
},

+ 6
- 6
src/views/searchView.ts View File

@ -217,15 +217,15 @@ export class SearchView extends ViewBase {
};
}
): (maxCount: number | undefined) => Promise<SearchQueryResult> {
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 {

Loading…
Cancel
Save