|
|
@@ -12,6 +12,8 @@ const { isAfter, addHours } = require('date-fns');
|
|
|
const contributors = require('../../../../resource/Contributor');
|
|
|
|
|
|
let expiredAt;
|
|
|
+let contributorsCache = contributors;
|
|
|
+
|
|
|
|
|
|
module.exports = (crowi) => {
|
|
|
|
|
|
@@ -21,24 +23,21 @@ module.exports = (crowi) => {
|
|
|
|
|
|
if (expiredAt == null || isAfter(now, expiredAt) || growiCloudUri != null) {
|
|
|
const url = new URL('_api/staffCredit', growiCloudUri);
|
|
|
+ const growiContributors = contributors.slice(0, 1);
|
|
|
+ const otherContributors = contributors.slice(1);
|
|
|
try {
|
|
|
const gcContributorsRes = await axios.get(url.toString());
|
|
|
- // prevent merge gcContributors to contributors more than once
|
|
|
- if (contributors[1].sectionName !== 'GROWI-cloud') {
|
|
|
- contributors.splice(1, 0, gcContributorsRes.data);
|
|
|
- }
|
|
|
- else {
|
|
|
- contributors.splice(1, 1, gcContributorsRes.data);
|
|
|
- }
|
|
|
+ const gcContributors = gcContributorsRes.data;
|
|
|
// caching 'expiredAt' for 1 hour
|
|
|
expiredAt = addHours(now, 1);
|
|
|
+ // caching merged contributors
|
|
|
+ contributorsCache = growiContributors.concat(gcContributors, otherContributors);
|
|
|
}
|
|
|
catch (err) {
|
|
|
- logger.warn('cannot display GROWI.cloud staffcredit');
|
|
|
- return res.apiv3();
|
|
|
+ logger.warn('Getting GROWI.cloud staffcredit is failed');
|
|
|
}
|
|
|
}
|
|
|
- return res.apiv3({ contributors });
|
|
|
+ return res.apiv3({ contributorsCache });
|
|
|
});
|
|
|
|
|
|
return router;
|