upd: cache instance sponsors
This commit is contained in:
parent
cc1017b2af
commit
dcd6eee627
|
@ -34,10 +34,13 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
|
||||||
) {
|
) {
|
||||||
super(meta, paramDef, async (ps, me) => {
|
super(meta, paramDef, async (ps, me) => {
|
||||||
let totalSponsors;
|
let totalSponsors;
|
||||||
const cachedSponsors = await this.redisClient.get('sponsors');
|
const cachedSponsors = await this.redisClient.get('sponsors');
|
||||||
|
const cachedInstanceSponsors = await this.redisClient.get('instanceSponsors');
|
||||||
|
|
||||||
if (!ps.forceUpdate && !ps.instance && cachedSponsors) {
|
if (!ps.forceUpdate && !ps.instance && cachedSponsors) {
|
||||||
totalSponsors = JSON.parse(cachedSponsors);
|
totalSponsors = JSON.parse(cachedSponsors);
|
||||||
|
} else if (ps.instance && !ps.forceUpdate && cachedInstanceSponsors) {
|
||||||
|
totalSponsors = JSON.parse(cachedInstanceSponsors);
|
||||||
} else if (!ps.instance) {
|
} else if (!ps.instance) {
|
||||||
try {
|
try {
|
||||||
const backers = await fetch('https://opencollective.com/sharkey/tiers/backer/all.json').then((response) => response.json());
|
const backers = await fetch('https://opencollective.com/sharkey/tiers/backer/all.json').then((response) => response.json());
|
||||||
|
@ -66,6 +69,8 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
|
||||||
|
|
||||||
// Remove possible duplicates
|
// Remove possible duplicates
|
||||||
totalSponsors = [...new Map(allSponsors.map(v => [v.profile, v])).values()];
|
totalSponsors = [...new Map(allSponsors.map(v => [v.profile, v])).values()];
|
||||||
|
|
||||||
|
await this.redisClient.set('instanceSponsors', JSON.stringify(totalSponsors), 'EX', 3600);
|
||||||
} else {
|
} else {
|
||||||
totalSponsors = [];
|
totalSponsors = [];
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue