computeProgress()

in public/components/runningReindex.react.js [40:60]


    computeProgress(reindex) {
        const waitMins = 15;
        let progress = 0;
        // if documentsExpected is 0, the server hasn't yet started the reindex, if it is non-zero
        // we'll display the actual reindex progress.
        if (reindex.documentsExpected !== 0) {
            progress = reindex.documentsIndexed / reindex.documentsExpected * 100;
        } else {
            // Express progress as a waitMins-derived percentage so that the progress bar
            // fills to 100% at start and ticks down towards 0%
            const elapsedMins = (new Date().valueOf() - new Date(reindex.startTime).valueOf()) / 60000;
            progress = -100 + (elapsedMins * (100 / waitMins));
            // At this point the reindex has failed to start within 15 mins. Setting progress to 101
            // means we can re-fill the progress bar, re-display the cancel button and display a
            // meaningful message. It will remain in this state until either the reindex starts or
            // it is cancelled by the user. It's clunky and this entire component could do with some
            // additional thought but it's better than we have currently.
            progress = (progress > -1) ? -101 : progress;
        }
        return progress;
    }