aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorNoah Loomans <noahloomans@gmail.com>2018-02-16 22:35:17 +0100
committerNoah Loomans <noahloomans@gmail.com>2018-02-16 22:35:17 +0100
commitaa6e144bfd0de1ae0b3d6506009a761f86b7e585 (patch)
treea71b4aea06e04fcc7c86506ea4251e60b8e5fa91 /src
parent71c297bab735ef06d2de0643a95ea9ee28b64479 (diff)
Simplify caching logic
Diffstat (limited to 'src')
-rw-r--r--src/server/lib/getMeetingpointData.js18
1 files changed, 9 insertions, 9 deletions
diff --git a/src/server/lib/getMeetingpointData.js b/src/server/lib/getMeetingpointData.js
index e50fe5f..5781023 100644
--- a/src/server/lib/getMeetingpointData.js
+++ b/src/server/lib/getMeetingpointData.js
@@ -1,6 +1,7 @@
const Promise = require('bluebird');
const cheerio = require('cheerio');
const iconv = require('iconv-lite');
+const debounce = require('promise-debounce');
const _ = require('lodash');
const request = Promise.promisify(require('request'));
@@ -57,8 +58,6 @@ function getAltText(page) {
}
function requestData() {
- lastUpdate = new Date();
-
const navbarRequests = [
request('http://www.meetingpointmco.nl/Roosters-AL/doc/dagroosters/frames/navbar.htm', { timeout: 5000 }),
request('http://www.meetingpointmco.nl/Roosters-AL/doc/basisroosters/frames/navbar.htm', { timeout: 5000 }),
@@ -90,22 +89,23 @@ function requestData() {
};
});
- meetingpointData = {
+ return {
users: _.uniqBy(_.flatten([teachersWithAlts, users]), user => `${user.type}/${user.value}`),
dailyScheduleWeeks,
basisScheduleWeeks,
};
-
- return meetingpointData;
});
});
}
function getMeetingpointData() {
- if (lastUpdate == null || new Date() - lastUpdate > 30 * 60 * 1000) { // 30 minutes
- return requestData();
- } else if (!meetingpointData) {
- return Promise.reject();
+ if (meetingpointData == null || new Date() - lastUpdate > 30 * 60 * 1000) { // 30 minutes
+ return requestData().then((meetingpointData_) => {
+ lastUpdate = new Date();
+ meetingpointData = meetingpointData_;
+
+ return meetingpointData;
+ });
}
return Promise.resolve(meetingpointData);