Skip to content

Commit a33e02e

Browse files
committed
fix: address performance review feedback
1 parent 4d529f4 commit a33e02e

9 files changed

Lines changed: 35 additions & 29 deletions

File tree

AGENTS.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -389,7 +389,7 @@ Five sections in order:
389389
390390
### Blog Post (/blog/[slug])
391391
Editorial layout:
392-
```
392+
```text
393393
[Cover image — full width, 1200x630px]
394394
CATEGORY BADGE
395395
Title (JetBrains Mono, H1)
@@ -563,4 +563,4 @@ const [products, posts] = await Promise.all([
563563
564564
---
565565
566-
*Last updated: May 2026*
566+
*Last updated: May 2026*

src/app/(public)/blog/[slug]/page.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
import type { Metadata } from "next";
22
import Image from "next/image";
33
import { notFound } from "next/navigation";
4+
import { cache } from "react";
45
import { and, desc, eq } from "drizzle-orm";
56
import PostContent, {
67
type TiptapJson,
78
} from "@/components/blog/PostContent";
89
import Badge from "@/components/ui/Badge";
910
import { blogPosts, db } from "@/db";
10-
import { getOptimisedUrl } from "@/lib/cloudinary-url";
11+
import { getOptimisedUrl } from "@/lib/cloudinary";
1112

1213
export const revalidate = 3600;
1314

@@ -33,7 +34,7 @@ function isTiptapJson(value: unknown): value is TiptapJson {
3334
return typeof value === "object" && value !== null && !Array.isArray(value);
3435
}
3536

36-
async function getPublishedPostBySlug(slug: string) {
37+
const getPublishedPostBySlug = cache(async (slug: string) => {
3738
try {
3839
const [post] = await db
3940
.select()
@@ -45,7 +46,7 @@ async function getPublishedPostBySlug(slug: string) {
4546
} catch {
4647
return null;
4748
}
48-
}
49+
});
4950

5051
export async function generateStaticParams() {
5152
if (process.env.CI === "true") {

src/app/(public)/contact/page.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import type { Metadata } from "next";
22
import ContactForm from "@/components/contact/ContactForm";
33

4+
export const revalidate = 3600;
5+
46
const title = "Contact — CodedDevs Technology LTD";
57
const description =
68
"Get in touch with the CodedDevs team. Partnerships, press, investment, and general enquiries.";

src/app/(public)/products/[slug]/page.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
import type { Metadata } from "next";
22
import Image from "next/image";
33
import { notFound } from "next/navigation";
4+
import { cache } from "react";
45
import { eq } from "drizzle-orm";
56
import Badge from "@/components/ui/Badge";
67
import Button from "@/components/ui/Button";
78
import { db, products } from "@/db";
8-
import { getOptimisedUrl } from "@/lib/cloudinary-url";
9+
import { getOptimisedUrl } from "@/lib/cloudinary";
910
import type { ProductSelect } from "@/types";
1011

1112
export const revalidate = 3600;
@@ -35,7 +36,7 @@ function statusVariant(status: ProductSelect["status"]) {
3536
return "muted";
3637
}
3738

38-
async function getProductBySlug(slug: string) {
39+
const getProductBySlug = cache(async (slug: string) => {
3940
try {
4041
const [product] = await db
4142
.select()
@@ -47,7 +48,7 @@ async function getProductBySlug(slug: string) {
4748
} catch {
4849
return null;
4950
}
50-
}
51+
});
5152

5253
export async function generateStaticParams() {
5354
if (process.env.CI === "true") {

src/app/(public)/team/page.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import Image from "next/image";
33
import { asc, eq } from "drizzle-orm";
44
import Card from "@/components/ui/Card";
55
import { db, teamMembers } from "@/db";
6-
import { getOptimisedUrl } from "@/lib/cloudinary-url";
6+
import { getOptimisedUrl } from "@/lib/cloudinary";
77
import type { TeamMember } from "@/types";
88

99
export const revalidate = 3600;

src/app/sitemap.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ import type { MetadataRoute } from "next";
22
import { desc, eq } from "drizzle-orm";
33
import { blogPosts, db, products } from "@/db";
44

5+
export const revalidate = 3600;
6+
57
const baseUrl = "https://codeddevs.com";
68

79
const staticRoutes = [

src/components/admin/ImageUpload.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import Image from "next/image";
44
import { useRef, useState } from "react";
55
import Button from "@/components/ui/Button";
6-
import { getOptimisedUrl } from "@/lib/cloudinary-url";
6+
import { getOptimisedUrl } from "@/lib/cloudinary";
77

88
type ImageUploadProps = {
99
value: string | null;

src/lib/cloudinary-url.ts

Lines changed: 0 additions & 15 deletions
This file was deleted.

src/lib/cloudinary.ts

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,27 @@
1-
import { getOptimisedUrl } from "@/lib/cloudinary-url";
1+
export function getOptimisedUrl(url: string | null | undefined): string {
2+
if (!url) {
3+
return "";
4+
}
25

3-
export { getOptimisedUrl };
6+
if (!url.includes("res.cloudinary.com") || !url.includes("/upload/")) {
7+
return url;
8+
}
9+
10+
if (url.includes("/upload/f_auto,q_auto/")) {
11+
return url;
12+
}
13+
14+
return url.replace("/upload/", "/upload/f_auto,q_auto/");
15+
}
416

517
export async function uploadToCloudinary(
618
fileBuffer: Buffer,
719
filename: string,
820
) {
9-
const { v2: cloudinary } = await import("cloudinary");
21+
const importCloudinary = new Function("return import('cloudinary')") as () => Promise<
22+
typeof import("cloudinary")
23+
>;
24+
const { v2: cloudinary } = await importCloudinary();
1025
const publicId = filename.replace(/\.[^/.]+$/, "");
1126

1227
cloudinary.config({
@@ -33,7 +48,7 @@ export async function uploadToCloudinary(
3348
return;
3449
}
3550

36-
resolve(getOptimisedUrl(result.secure_url));
51+
resolve(result.secure_url);
3752
},
3853
);
3954

0 commit comments

Comments
 (0)