mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 17:59:23 -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 { CommitInfo, ReferenceInfo, ReferenceType } from '../model/commit';
|
||||||
import { detectLanguage } from './utils/detect_language';
|
import { detectLanguage } from './utils/detect_language';
|
||||||
|
|
||||||
const HEAD = 'HEAD';
|
export const HEAD = 'HEAD';
|
||||||
const REFS_HEADS = 'refs/heads/';
|
const REFS_HEADS = 'refs/heads/';
|
||||||
export const DEFAULT_TREE_CHILDREN_LIMIT = 50;
|
export const DEFAULT_TREE_CHILDREN_LIMIT = 50;
|
||||||
|
|
||||||
|
@ -129,7 +129,7 @@ export class GitOperations {
|
||||||
|
|
||||||
public async getCommit(uri: RepositoryUri, revision: string): Promise<Commit> {
|
public async getCommit(uri: RepositoryUri, revision: string): Promise<Commit> {
|
||||||
const repo = await this.openRepo(uri);
|
const repo = await this.openRepo(uri);
|
||||||
if (revision.toUpperCase() === 'HEAD') {
|
if (revision.toUpperCase() === HEAD) {
|
||||||
return await repo.getHeadCommit();
|
return await repo.getHeadCommit();
|
||||||
}
|
}
|
||||||
// branches and tags
|
// branches and tags
|
||||||
|
|
|
@ -17,7 +17,7 @@ import {
|
||||||
LspIncIndexRequest,
|
LspIncIndexRequest,
|
||||||
RepositoryUri,
|
RepositoryUri,
|
||||||
} from '../../model';
|
} from '../../model';
|
||||||
import { GitOperations } from '../git_operations';
|
import { GitOperations, HEAD } from '../git_operations';
|
||||||
import { EsClient } from '../lib/esqueue';
|
import { EsClient } from '../lib/esqueue';
|
||||||
import { Logger } from '../log';
|
import { Logger } from '../log';
|
||||||
import { LspService } from '../lsp/lsp_service';
|
import { LspService } from '../lsp/lsp_service';
|
||||||
|
@ -126,7 +126,7 @@ export class LspIncrementalIndexer extends LspIndexer {
|
||||||
try {
|
try {
|
||||||
const { workspaceRepo } = await this.lspService.workspaceHandler.openWorkspace(
|
const { workspaceRepo } = await this.lspService.workspaceHandler.openWorkspace(
|
||||||
this.repoUri,
|
this.repoUri,
|
||||||
'head'
|
HEAD
|
||||||
);
|
);
|
||||||
const workspaceDir = workspaceRepo.workdir();
|
const workspaceDir = workspaceRepo.workdir();
|
||||||
if (this.diff) {
|
if (this.diff) {
|
||||||
|
@ -136,7 +136,11 @@ export class LspIncrementalIndexer extends LspIndexer {
|
||||||
localRepoPath: workspaceDir,
|
localRepoPath: workspaceDir,
|
||||||
filePath: f.path,
|
filePath: f.path,
|
||||||
originPath: f.originPath,
|
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,
|
kind: f.kind,
|
||||||
originRevision: this.originRevision,
|
originRevision: this.originRevision,
|
||||||
};
|
};
|
||||||
|
|
|
@ -17,7 +17,7 @@ import {
|
||||||
} from '../../common/lsp_error_codes';
|
} from '../../common/lsp_error_codes';
|
||||||
import { toCanonicalUrl } from '../../common/uri_util';
|
import { toCanonicalUrl } from '../../common/uri_util';
|
||||||
import { Document, IndexStats, IndexStatsKey, LspIndexRequest, RepositoryUri } from '../../model';
|
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 { EsClient } from '../lib/esqueue';
|
||||||
import { Logger } from '../log';
|
import { Logger } from '../log';
|
||||||
import { LspService } from '../lsp/lsp_service';
|
import { LspService } from '../lsp/lsp_service';
|
||||||
|
@ -103,20 +103,24 @@ export class LspIndexer extends AbstractIndexer {
|
||||||
protected async *getIndexRequestIterator(): AsyncIterableIterator<LspIndexRequest> {
|
protected async *getIndexRequestIterator(): AsyncIterableIterator<LspIndexRequest> {
|
||||||
let repo;
|
let repo;
|
||||||
try {
|
try {
|
||||||
const {
|
const { workspaceRepo } = await this.lspService.workspaceHandler.openWorkspace(
|
||||||
workspaceRepo,
|
this.repoUri,
|
||||||
workspaceRevision,
|
HEAD
|
||||||
} = await this.lspService.workspaceHandler.openWorkspace(this.repoUri, 'head');
|
);
|
||||||
repo = workspaceRepo;
|
repo = workspaceRepo;
|
||||||
const workspaceDir = workspaceRepo.workdir();
|
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) {
|
for await (const file of fileIterator) {
|
||||||
const filePath = file.path!;
|
const filePath = file.path!;
|
||||||
const req: LspIndexRequest = {
|
const req: LspIndexRequest = {
|
||||||
repoUri: this.repoUri,
|
repoUri: this.repoUri,
|
||||||
localRepoPath: workspaceDir,
|
localRepoPath: workspaceDir,
|
||||||
filePath,
|
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;
|
yield req;
|
||||||
}
|
}
|
||||||
|
@ -133,7 +137,7 @@ export class LspIndexer extends AbstractIndexer {
|
||||||
|
|
||||||
protected async getIndexRequestCount(): Promise<number> {
|
protected async getIndexRequestCount(): Promise<number> {
|
||||||
try {
|
try {
|
||||||
return await this.gitOps.countRepoFiles(this.repoUri, 'head');
|
return await this.gitOps.countRepoFiles(this.repoUri, HEAD);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
if (this.isCancelled()) {
|
if (this.isCancelled()) {
|
||||||
this.log.debug(`Indexer got cancelled. Skip get index count error.`);
|
this.log.debug(`Indexer got cancelled. Skip get index count error.`);
|
||||||
|
|
|
@ -16,7 +16,7 @@ import {
|
||||||
WorkerProgress,
|
WorkerProgress,
|
||||||
WorkerReservedProgress,
|
WorkerReservedProgress,
|
||||||
} from '../../model';
|
} from '../../model';
|
||||||
import { GitOperations } from '../git_operations';
|
import { GitOperations, HEAD } from '../git_operations';
|
||||||
import { IndexerFactory } from '../indexer';
|
import { IndexerFactory } from '../indexer';
|
||||||
import { EsClient, Esqueue } from '../lib/esqueue';
|
import { EsClient, Esqueue } from '../lib/esqueue';
|
||||||
import { Logger } from '../log';
|
import { Logger } from '../log';
|
||||||
|
@ -171,7 +171,7 @@ export class IndexWorker extends AbstractWorker {
|
||||||
|
|
||||||
protected async getTimeoutMs(payload: any) {
|
protected async getTimeoutMs(payload: any) {
|
||||||
try {
|
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();
|
let timeout = moment.duration(1, 'hour').asMilliseconds();
|
||||||
if (totalCount > 0) {
|
if (totalCount > 0) {
|
||||||
// timeout = ln(file_count) in hour
|
// timeout = ln(file_count) in hour
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue