From dcd6eee627b20c1dfa2dc38a9fbd9e38d4d878d5 Mon Sep 17 00:00:00 2001 From: Marie Date: Wed, 2 Oct 2024 18:27:11 +0200 Subject: [PATCH] upd: cache instance sponsors --- packages/backend/src/server/api/endpoints/sponsors.ts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/packages/backend/src/server/api/endpoints/sponsors.ts b/packages/backend/src/server/api/endpoints/sponsors.ts index 3c3cdd7808..34a3ed70dd 100644 --- a/packages/backend/src/server/api/endpoints/sponsors.ts +++ b/packages/backend/src/server/api/endpoints/sponsors.ts @@ -34,10 +34,13 @@ export default class extends Endpoint { // eslint- ) { super(meta, paramDef, async (ps, me) => { 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) { totalSponsors = JSON.parse(cachedSponsors); + } else if (ps.instance && !ps.forceUpdate && cachedInstanceSponsors) { + totalSponsors = JSON.parse(cachedInstanceSponsors); } else if (!ps.instance) { try { 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 { // eslint- // Remove possible duplicates totalSponsors = [...new Map(allSponsors.map(v => [v.profile, v])).values()]; + + await this.redisClient.set('instanceSponsors', JSON.stringify(totalSponsors), 'EX', 3600); } else { totalSponsors = []; }