refactor: move cache seconds calculation logic into reusable function (#4532)
* refactor: move cache seconds calculation logic into reusable function * dev --------- Co-authored-by: Alexandr <qwerty541zxc@gmail.com>
This commit is contained in:
1 parent
fde13639aa
commit
ade7d53653
6 files changed
+60
-60
No files matched your search
+7
-10
@@ -2,9 +2,9 @@
|
||||
|
||||
import { renderStatsCard } from "../src/cards/stats.js";
|
||||
import { blacklist } from "../src/common/blacklist.js";
|
||||
import { resolveCacheSeconds } from "../src/common/cache.js";
|
||||
import { whitelist } from "../src/common/envs.js";
|
||||
import {
|
||||
clampValue,
|
||||
CONSTANTS,
|
||||
parseArray,
|
||||
parseBoolean,
|
||||
@@ -103,15 +103,12 @@ export default async (req, res) => {
|
||||
showStats.includes("discussions_answered"),
|
||||
parseInt(commits_year, 10),
|
||||
);
|
||||
|
||||
let cacheSeconds = clampValue(
|
||||
parseInt(cache_seconds || CONSTANTS.CARD_CACHE_SECONDS, 10),
|
||||
CONSTANTS.TWELVE_HOURS,
|
||||
CONSTANTS.TWO_DAY,
|
||||
);
|
||||
cacheSeconds = process.env.CACHE_SECONDS
|
||||
? parseInt(process.env.CACHE_SECONDS, 10) || cacheSeconds
|
||||
: cacheSeconds;
|
||||
const cacheSeconds = resolveCacheSeconds({
|
||||
requested: cache_seconds,
|
||||
def: CONSTANTS.CARD_CACHE_SECONDS,
|
||||
min: CONSTANTS.TWELVE_HOURS,
|
||||
max: CONSTANTS.TWO_DAY,
|
||||
});
|
||||
|
||||
res.setHeader(
|
||||
"Cache-Control",
|
||||
|
||||
Reference in new issue
Block a user