mirror of
https://github.com/jakejarvis/jarv.is.git
synced 2025-04-26 09:05:22 -04:00
dramatically reduce the number of redis commands used for /api/hits
This commit is contained in:
parent
64caf0f88b
commit
77a44fdea7
@ -22,18 +22,16 @@ export const GET = async (): Promise<
|
||||
count: 99,
|
||||
});
|
||||
|
||||
// get the value (number of hits) for each key (the slug of the page) and pair them together
|
||||
const pages = await Promise.all(
|
||||
slugs[1].map(async (slug) => {
|
||||
const hits = (await redis.get(slug)) as number;
|
||||
return {
|
||||
slug,
|
||||
hits,
|
||||
};
|
||||
})
|
||||
);
|
||||
// get the value (number of hits) for each key (the slug of the page)
|
||||
const values = await redis.mget<string[]>(...slugs[1]);
|
||||
|
||||
// sort by hits
|
||||
// pair the slugs with their hit values
|
||||
const pages = slugs[1].map((slug, index) => ({
|
||||
slug,
|
||||
hits: parseInt(values[index], 10),
|
||||
}));
|
||||
|
||||
// sort descending by hits
|
||||
pages.sort((a, b) => b.hits - a.hits);
|
||||
|
||||
// calculate total hits
|
||||
|
@ -37,7 +37,7 @@
|
||||
"feed": "^4.2.2",
|
||||
"geist": "^1.3.1",
|
||||
"html-entities": "^2.5.3",
|
||||
"lucide-react": "0.484.0",
|
||||
"lucide-react": "0.485.0",
|
||||
"modern-normalize": "^3.0.1",
|
||||
"next": "15.3.0-canary.24",
|
||||
"obj-str": "^1.1.0",
|
||||
|
10
pnpm-lock.yaml
generated
10
pnpm-lock.yaml
generated
@ -69,8 +69,8 @@ importers:
|
||||
specifier: ^2.5.3
|
||||
version: 2.5.3
|
||||
lucide-react:
|
||||
specifier: 0.484.0
|
||||
version: 0.484.0(react@19.0.0)
|
||||
specifier: 0.485.0
|
||||
version: 0.485.0(react@19.0.0)
|
||||
modern-normalize:
|
||||
specifier: ^3.0.1
|
||||
version: 3.0.1
|
||||
@ -2388,8 +2388,8 @@ packages:
|
||||
lru-cache@5.1.1:
|
||||
resolution: {integrity: sha512-KpNARQA3Iwv+jTA0utUVVbrh+Jlrr1Fv0e56GGzAFOXN7dk/FviaDW8LHmK52DlcH4WP2n6gI8vN1aesBFgo9w==}
|
||||
|
||||
lucide-react@0.484.0:
|
||||
resolution: {integrity: sha512-oZy8coK9kZzvqhSgfbGkPtTgyjpBvs3ukLgDPv14dSOZtBtboryWF5o8i3qen7QbGg7JhiJBz5mK1p8YoMZTLQ==}
|
||||
lucide-react@0.485.0:
|
||||
resolution: {integrity: sha512-NvyQJ0LKyyCxL23nPKESlr/jmz8r7fJO1bkuptSNYSy0s8VVj4ojhX0YAgmE1e0ewfxUZjIlZpvH+otfTnla8Q==}
|
||||
peerDependencies:
|
||||
react: ^16.5.1 || ^17.0.0 || ^18.0.0 || ^19.0.0
|
||||
|
||||
@ -6167,7 +6167,7 @@ snapshots:
|
||||
dependencies:
|
||||
yallist: 3.1.1
|
||||
|
||||
lucide-react@0.484.0(react@19.0.0):
|
||||
lucide-react@0.485.0(react@19.0.0):
|
||||
dependencies:
|
||||
react: 19.0.0
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user