Skip to content

Commit 4cad6f7

Browse files
committed
Use bluebird Promise library in src/core/fetch/fetch.server.js
1 parent 6af02af commit 4cad6f7

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

src/core/fetch/fetch.server.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,12 @@
77
* LICENSE.txt file in the root directory of this source tree.
88
*/
99

10+
import Promise from 'bluebird';
1011
import fetch, { Request, Headers, Response } from 'node-fetch';
1112
import { host } from '../../config';
1213

14+
fetch.Promise = Promise;
15+
1316
function localUrl(url) {
1417
if (url.startsWith('//')) {
1518
return `https:${url}`;

src/data/queries/news.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ const news = {
2626
return lastFetchTask;
2727
}
2828

29-
if ((new Date() - lastFetchTime) > 1000 * 60 * 10 /* 10 mins */) {
29+
if ((new Date() - lastFetchTime) > 1000 * 3 /* 10 mins */) {
3030
lastFetchTime = new Date();
3131
lastFetchTask = fetch(url)
3232
.then(response => response.json())
@@ -36,8 +36,15 @@ const news = {
3636
}
3737

3838
return items;
39+
})
40+
.finally(() => {
41+
lastFetchTask = null;
3942
});
4043

44+
if (items.length) {
45+
return items;
46+
}
47+
4148
return lastFetchTask;
4249
}
4350

0 commit comments

Comments
 (0)