Skip to content

Commit 139a160

Browse files
authored
Way faster without spinner (#490)
1 parent 59b9d39 commit 139a160

File tree

3 files changed

+207
-964
lines changed

3 files changed

+207
-964
lines changed

lib/tldr.js

Lines changed: 4 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
const sample = require('lodash/sample');
44
const fs = require('fs-extra');
55
const ms = require('ms');
6-
const ora = require('ora');
76
const { EmptyCacheError, MissingPageError, MissingRenderPathError } = require('./errors');
87
const Cache = require('./cache');
98
const search = require('./search');
@@ -140,19 +139,15 @@ class Tldr {
140139
* @returns {Promise<any>} The index.
141140
*/
142141
updateCache() {
143-
return spinningPromise('Updating...', () => {
144-
return this.cache.update();
145-
});
142+
return this.cache.update();
146143
}
147144

148145
/**
149146
* Update the index.
150147
* @returns {Promise<any>} The index.
151148
*/
152149
updateIndex() {
153-
return spinningPromise('Creating index...', () => {
154-
return search.createIndex();
155-
});
150+
return search.createIndex();
156151
}
157152

158153
/**
@@ -204,13 +199,9 @@ class Tldr {
204199
if (this.config.skipUpdateWhenPageNotFound === true) {
205200
return '';
206201
}
207-
return spinningPromise('Page not found. Updating cache...', () => {
208-
return this.cache.update();
209-
})
202+
return this.cache.update()
210203
.then(() => {
211-
return spinningPromise('Creating index...', () => {
212-
return search.createIndex();
213-
});
204+
return search.createIndex();
214205
})
215206
.then(() => {
216207
// And then, try to check in cache again
@@ -263,24 +254,4 @@ class Tldr {
263254
}
264255
}
265256

266-
/**
267-
* Display a spinner while a task is running.
268-
* @param {string} text The text of the spinner.
269-
* @param {Function} factory A task to be run.
270-
* @returns {Promise<unknown>} A promise with the result of the task.
271-
*/
272-
function spinningPromise(text, factory) {
273-
const spinner = ora();
274-
spinner.start(text);
275-
return factory()
276-
.then((val) => {
277-
spinner.succeed();
278-
return val;
279-
})
280-
.catch((err) => {
281-
spinner.fail();
282-
throw err;
283-
});
284-
}
285-
286257
module.exports = Tldr;

0 commit comments

Comments
 (0)