Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Code] improve index progress calculation #32537

Merged
merged 1 commit into from
Mar 7, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions x-pack/plugins/code/server/indexer/abstract_indexer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
* you may not use this file except in compliance with the Elastic License.
*/

import moment from 'moment';

import { Indexer, IndexProgress, ProgressReporter } from '.';
import { IndexRequest, IndexStats, IndexStatsKey, RepositoryUri } from '../../model';
import { EsClient } from '../lib/esqueue';
Expand All @@ -16,6 +18,7 @@ export abstract class AbstractIndexer implements Indexer {
protected type: string = 'abstract';
protected cancelled: boolean = false;
protected indexCreator: IndexCreator;
protected INDEXER_PROGRESS_UPDATE_INTERVAL_MS = 1000;

constructor(
protected readonly repoUri: RepositoryUri,
Expand Down Expand Up @@ -44,7 +47,7 @@ export abstract class AbstractIndexer implements Indexer {

// Prepare all the index requests
let totalCount = 0;
let prevPercentage = 0;
let prevTimestamp = moment();
let successCount = 0;
let failCount = 0;
const statsBuffer: IndexStats[] = [];
Expand Down Expand Up @@ -83,9 +86,9 @@ export abstract class AbstractIndexer implements Indexer {
fail: failCount,
percentage: Math.floor((100 * (successCount + failCount)) / totalCount),
};
if (progress.percentage > prevPercentage + 5) {
if (moment().diff(prevTimestamp) > this.INDEXER_PROGRESS_UPDATE_INTERVAL_MS) {
progressReporter(progress);
prevPercentage = progress.percentage;
prevTimestamp = moment();
}
}
}
Expand Down