Skip to content

Commit

Permalink
Changed cpu schema version enforcement
Browse files Browse the repository at this point in the history
Fixed tooltip overlapping issue.
  • Loading branch information
UltimateDoge5 committed May 17, 2023
1 parent 0880f21 commit 9b61f4b
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 7 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
![PrimeCPU logo](./docs/banner.png)
![PrimeCPU logo](./public/banner.png)

A simple [web app](https://prime.pkozak.org) for comparing cpus. No bloat, just quick and easy comparison.
This project was build with backwards compatibility in mind, so that even 12-year-old cpus can be compared.
Expand Down
1 change: 1 addition & 0 deletions envs.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ declare namespace NodeJS {
interface ProcessEnv {
BROWSERLESS_URL: string;
BROWSERLESS_TOKEN: string;
MIN_SCHEMA_VERSION: string;
}
}

7 changes: 7 additions & 0 deletions src/app/cpu/[cpu]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,13 @@ const TableStructure: Table = {
unit: "$",
tooltip: "Manufacturer's suggested retail price. For AMDs may not be as accurate.",
},
cache: {
title: "Cache",
path: "cache",
type: "number",
unit: "B",
tooltip: "Amount of L3 cache. (Intel provides only L3 cache)",
}
},
"CPU specifications": {
baseFrequency: {
Expand Down
2 changes: 1 addition & 1 deletion src/components/tooltip.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const Tooltip = ({ tip }: { tip: string }) => {
/>
</svg>

<div className="absolute top-full z-10 w-max max-w-md rounded-md bg-gray-800 p-2 text-sm text-white opacity-0 transition-all peer-hover:opacity-100">
<div className="pointer-events-none absolute top-full z-10 w-max max-w-md rounded-md bg-gray-800 p-2 text-sm text-white opacity-0 transition-all peer-hover:pointer-events-auto peer-hover:opacity-100">
{tip}
</div>
</div>
Expand Down
4 changes: 2 additions & 2 deletions src/util/scrapers/amd.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ let $: CheerioAPI;
const scrapeAMD = async (redis: Redis, model: string, noCache: boolean) =>
new Promise<CPU>(async (resolve, reject) => {
let cpu: CPU | null = !noCache ? (await redis.json.get(model.replace(/ /g, "-"), "$"))?.[0] : null;
if (cpu !== null && cpu?.schemaVer >= parseFloat(process.env.MIN_SCHEMA_VERSION || "1.1")) return resolve(cpu);
if (cpu !== null && cpu?.schemaVer === parseFloat(process.env.MIN_SCHEMA_VERSION)) return resolve(cpu);

const url = AMD_PRODUCTS.find((item) => item.name.replace("™", "").toLowerCase() === model)?.url;
if (!url) {
Expand Down Expand Up @@ -86,7 +86,7 @@ const scrapeAMD = async (redis: Redis, model: string, noCache: boolean) =>
source: url,
ref: "/cpu/" + model,
scrapedAt: new Date().toString(),
schemaVer: 1.2,
schemaVer: parseFloat(process.env.MIN_SCHEMA_VERSION),
};

if (process.env.NODE_ENV !== "test") await redis.json.set(model, "$", cpu as Record<string, any>);
Expand Down
5 changes: 2 additions & 3 deletions src/util/scrapers/intel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ let $: CheerioAPI;
const scrapeIntel = async (redis: Redis, model: string, noCache: boolean) =>
new Promise<CPU>(async (resolve, reject) => {
let cpu: CPU | null = !noCache ? (await redis.json.get(`intel-${model.replace(/ /g, "-")}`, "$"))?.[0] : null;

if (cpu !== null && cpu?.schemaVer >= parseFloat(process.env.MIN_SCHEMA_VERSION || "1.2")) return resolve(cpu);
if (cpu !== null && cpu?.schemaVer === parseFloat(process.env.MIN_SCHEMA_VERSION)) return resolve(cpu);

const token = (await redis.get<string>("intel-token")) ?? (await refreshToken(redis));

Expand Down Expand Up @@ -113,7 +112,7 @@ const scrapeIntel = async (redis: Redis, model: string, noCache: boolean) =>
source: url,
ref: "/cpu/intel-" + model,
scrapedAt: new Date().toString(),
schemaVer: 1.2,
schemaVer: parseFloat(process.env.MIN_SCHEMA_VERSION),
};

// if (process.env.NODE_ENV === "production" || req.query["no-cache"] !== undefined)
Expand Down

1 comment on commit 9b61f4b

@vercel
Copy link

@vercel vercel bot commented on 9b61f4b May 19, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.