mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 09:48:58 -04:00
[Code] apply loading for search and limit indexed document size (#36510)
This commit is contained in:
parent
8c0f8c1931
commit
7ca9b46e9c
4 changed files with 37 additions and 14 deletions
7
x-pack/plugins/code/common/file.ts
Normal file
7
x-pack/plugins/code/common/file.ts
Normal file
|
@ -0,0 +1,7 @@
|
|||
/*
|
||||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
|
||||
* or more contributor license agreements. Licensed under the Elastic License;
|
||||
* you may not use this file except in compliance with the Elastic License.
|
||||
*/
|
||||
|
||||
export const TEXT_FILE_LIMIT = 1024 * 1024; // 1mb
|
|
@ -4,7 +4,7 @@
|
|||
* you may not use this file except in compliance with the Elastic License.
|
||||
*/
|
||||
|
||||
import { EuiFlexItem, EuiSpacer, EuiTitle } from '@elastic/eui';
|
||||
import { EuiFlexItem, EuiLoadingSpinner, EuiSpacer, EuiText, EuiTitle } from '@elastic/eui';
|
||||
import querystring from 'querystring';
|
||||
import React from 'react';
|
||||
import { connect } from 'react-redux';
|
||||
|
@ -119,11 +119,22 @@ class SearchPage extends React.PureComponent<Props, State> {
|
|||
scope,
|
||||
documentSearchResults,
|
||||
languages,
|
||||
isLoading,
|
||||
repositories,
|
||||
repositorySearchResults,
|
||||
} = this.props;
|
||||
|
||||
let mainComp = (
|
||||
let mainComp = isLoading ? (
|
||||
<div>
|
||||
<EuiSpacer size="xl" />
|
||||
<EuiSpacer size="xl" />
|
||||
<EuiText textAlign="center">Loading...</EuiText>
|
||||
<EuiSpacer size="m" />
|
||||
<EuiText textAlign="center">
|
||||
<EuiLoadingSpinner size="xl" />
|
||||
</EuiText>
|
||||
</div>
|
||||
) : (
|
||||
<EmptyPlaceholder
|
||||
query={query}
|
||||
toggleOptionsFlyout={() => {
|
||||
|
|
|
@ -8,6 +8,7 @@ import fs from 'fs';
|
|||
import util from 'util';
|
||||
|
||||
import { ProgressReporter } from '.';
|
||||
import { TEXT_FILE_LIMIT } from '../../common/file';
|
||||
import { toCanonicalUrl } from '../../common/uri_util';
|
||||
import { Document, IndexStats, IndexStatsKey, LspIndexRequest, RepositoryUri } from '../../model';
|
||||
import { GitOperations } from '../git_operations';
|
||||
|
@ -185,6 +186,21 @@ export class LspIndexer extends AbstractIndexer {
|
|||
const lspDocUri = toCanonicalUrl({ repoUri, revision, file: filePath, schema: 'git:' });
|
||||
const symbolNames = new Set<string>();
|
||||
|
||||
const localFilePath = `${localRepoPath}${filePath}`;
|
||||
const lstat = util.promisify(fs.lstat);
|
||||
const stat = await lstat(localFilePath);
|
||||
|
||||
const readLink = util.promisify(fs.readlink);
|
||||
const readFile = util.promisify(fs.readFile);
|
||||
const content = stat.isSymbolicLink()
|
||||
? await readLink(localFilePath, 'utf8')
|
||||
: await readFile(localFilePath, 'utf8');
|
||||
|
||||
if (content.length > TEXT_FILE_LIMIT) {
|
||||
this.log.debug(`File size exceeds limit. Skip index.`);
|
||||
return stats;
|
||||
}
|
||||
|
||||
try {
|
||||
const lang = detectLanguageByFilename(filePath);
|
||||
// filter file by language
|
||||
|
@ -219,16 +235,6 @@ export class LspIndexer extends AbstractIndexer {
|
|||
this.log.error(error);
|
||||
}
|
||||
|
||||
const localFilePath = `${localRepoPath}${filePath}`;
|
||||
const lstat = util.promisify(fs.lstat);
|
||||
const stat = await lstat(localFilePath);
|
||||
|
||||
const readLink = util.promisify(fs.readlink);
|
||||
const readFile = util.promisify(fs.readFile);
|
||||
const content = stat.isSymbolicLink()
|
||||
? await readLink(localFilePath, 'utf8')
|
||||
: await readFile(localFilePath, 'utf8');
|
||||
|
||||
const language = await detectLanguage(filePath, Buffer.from(content));
|
||||
const body: Document = {
|
||||
repoUri,
|
||||
|
|
|
@ -20,8 +20,7 @@ import { detectLanguage } from '../utils/detect_language';
|
|||
import { CodeServerRouter } from '../security';
|
||||
import { RepositoryObjectClient } from '../search';
|
||||
import { EsClientWithRequest } from '../utils/esclient_with_request';
|
||||
|
||||
const TEXT_FILE_LIMIT = 1024 * 1024; // 1mb
|
||||
import { TEXT_FILE_LIMIT } from '../../common/file';
|
||||
|
||||
export function fileRoute(server: CodeServerRouter, options: ServerOptions) {
|
||||
async function repoExists(req: hapi.Request, repoUri: string) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue