mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 09:48:58 -04:00
[Code] always enforce HEAD revision for indexing even when repo get updated during index (#39528)
This commit is contained in:
parent
91a5a54c78
commit
86ec72d443
4 changed files with 23 additions and 15 deletions
|
@ -29,7 +29,7 @@ import { FileTree, FileTreeItemType, RepositoryUri, sortFileTree } from '../mode
|
|||
import { CommitInfo, ReferenceInfo, ReferenceType } from '../model/commit';
|
||||
import { detectLanguage } from './utils/detect_language';
|
||||
|
||||
const HEAD = 'HEAD';
|
||||
export const HEAD = 'HEAD';
|
||||
const REFS_HEADS = 'refs/heads/';
|
||||
export const DEFAULT_TREE_CHILDREN_LIMIT = 50;
|
||||
|
||||
|
@ -129,7 +129,7 @@ export class GitOperations {
|
|||
|
||||
public async getCommit(uri: RepositoryUri, revision: string): Promise<Commit> {
|
||||
const repo = await this.openRepo(uri);
|
||||
if (revision.toUpperCase() === 'HEAD') {
|
||||
if (revision.toUpperCase() === HEAD) {
|
||||
return await repo.getHeadCommit();
|
||||
}
|
||||
// branches and tags
|
||||
|
|
|
@ -17,7 +17,7 @@ import {
|
|||
LspIncIndexRequest,
|
||||
RepositoryUri,
|
||||
} from '../../model';
|
||||
import { GitOperations } from '../git_operations';
|
||||
import { GitOperations, HEAD } from '../git_operations';
|
||||
import { EsClient } from '../lib/esqueue';
|
||||
import { Logger } from '../log';
|
||||
import { LspService } from '../lsp/lsp_service';
|
||||
|
@ -126,7 +126,7 @@ export class LspIncrementalIndexer extends LspIndexer {
|
|||
try {
|
||||
const { workspaceRepo } = await this.lspService.workspaceHandler.openWorkspace(
|
||||
this.repoUri,
|
||||
'head'
|
||||
HEAD
|
||||
);
|
||||
const workspaceDir = workspaceRepo.workdir();
|
||||
if (this.diff) {
|
||||
|
@ -136,7 +136,11 @@ export class LspIncrementalIndexer extends LspIndexer {
|
|||
localRepoPath: workspaceDir,
|
||||
filePath: f.path,
|
||||
originPath: f.originPath,
|
||||
revision: this.revision,
|
||||
// Always use HEAD for now until we have multi revision.
|
||||
// Also, since the workspace might get updated during the index, we always
|
||||
// want the revision to keep updated so that lsp proxy could pass the revision
|
||||
// check per discussion here: https://github.com/elastic/code/issues/1317#issuecomment-504615833
|
||||
revision: HEAD,
|
||||
kind: f.kind,
|
||||
originRevision: this.originRevision,
|
||||
};
|
||||
|
|
|
@ -17,7 +17,7 @@ import {
|
|||
} from '../../common/lsp_error_codes';
|
||||
import { toCanonicalUrl } from '../../common/uri_util';
|
||||
import { Document, IndexStats, IndexStatsKey, LspIndexRequest, RepositoryUri } from '../../model';
|
||||
import { GitOperations } from '../git_operations';
|
||||
import { GitOperations, HEAD } from '../git_operations';
|
||||
import { EsClient } from '../lib/esqueue';
|
||||
import { Logger } from '../log';
|
||||
import { LspService } from '../lsp/lsp_service';
|
||||
|
@ -103,20 +103,24 @@ export class LspIndexer extends AbstractIndexer {
|
|||
protected async *getIndexRequestIterator(): AsyncIterableIterator<LspIndexRequest> {
|
||||
let repo;
|
||||
try {
|
||||
const {
|
||||
workspaceRepo,
|
||||
workspaceRevision,
|
||||
} = await this.lspService.workspaceHandler.openWorkspace(this.repoUri, 'head');
|
||||
const { workspaceRepo } = await this.lspService.workspaceHandler.openWorkspace(
|
||||
this.repoUri,
|
||||
HEAD
|
||||
);
|
||||
repo = workspaceRepo;
|
||||
const workspaceDir = workspaceRepo.workdir();
|
||||
const fileIterator = await this.gitOps.iterateRepo(this.repoUri, 'head');
|
||||
const fileIterator = await this.gitOps.iterateRepo(this.repoUri, HEAD);
|
||||
for await (const file of fileIterator) {
|
||||
const filePath = file.path!;
|
||||
const req: LspIndexRequest = {
|
||||
repoUri: this.repoUri,
|
||||
localRepoPath: workspaceDir,
|
||||
filePath,
|
||||
revision: workspaceRevision,
|
||||
// Always use HEAD for now until we have multi revision.
|
||||
// Also, since the workspace might get updated during the index, we always
|
||||
// want the revision to keep updated so that lsp proxy could pass the revision
|
||||
// check per discussion here: https://github.com/elastic/code/issues/1317#issuecomment-504615833
|
||||
revision: HEAD,
|
||||
};
|
||||
yield req;
|
||||
}
|
||||
|
@ -133,7 +137,7 @@ export class LspIndexer extends AbstractIndexer {
|
|||
|
||||
protected async getIndexRequestCount(): Promise<number> {
|
||||
try {
|
||||
return await this.gitOps.countRepoFiles(this.repoUri, 'head');
|
||||
return await this.gitOps.countRepoFiles(this.repoUri, HEAD);
|
||||
} catch (error) {
|
||||
if (this.isCancelled()) {
|
||||
this.log.debug(`Indexer got cancelled. Skip get index count error.`);
|
||||
|
|
|
@ -16,7 +16,7 @@ import {
|
|||
WorkerProgress,
|
||||
WorkerReservedProgress,
|
||||
} from '../../model';
|
||||
import { GitOperations } from '../git_operations';
|
||||
import { GitOperations, HEAD } from '../git_operations';
|
||||
import { IndexerFactory } from '../indexer';
|
||||
import { EsClient, Esqueue } from '../lib/esqueue';
|
||||
import { Logger } from '../log';
|
||||
|
@ -171,7 +171,7 @@ export class IndexWorker extends AbstractWorker {
|
|||
|
||||
protected async getTimeoutMs(payload: any) {
|
||||
try {
|
||||
const totalCount = await this.gitOps.countRepoFiles(payload.uri, 'head');
|
||||
const totalCount = await this.gitOps.countRepoFiles(payload.uri, HEAD);
|
||||
let timeout = moment.duration(1, 'hour').asMilliseconds();
|
||||
if (totalCount > 0) {
|
||||
// timeout = ln(file_count) in hour
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue