perf improvements

This commit is contained in:
Michael Freno
2026-01-04 14:53:30 -05:00
parent 111712e969
commit a620a9f4c5
10 changed files with 303 additions and 1750 deletions

BIN
bun.lockb

Binary file not shown.

View File

@@ -75,6 +75,8 @@
"playwright": "^1.57.0", "playwright": "^1.57.0",
"prettier": "^3.7.4", "prettier": "^3.7.4",
"prettier-plugin-tailwindcss": "^0.7.2", "prettier-plugin-tailwindcss": "^0.7.2",
"trpc-panel": "^1.3.4" "rollup-plugin-visualizer": "^6.0.5",
"trpc-panel": "^1.3.4",
"vite-bundle-visualizer": "^1.2.1"
} }
} }

File diff suppressed because it is too large Load Diff

View File

@@ -265,12 +265,17 @@ export function LeftBar() {
const glitchChars = "!@#$%^&*()_+-=[]{}|;':\",./<>?~`"; const glitchChars = "!@#$%^&*()_+-=[]{}|;':\",./<>?~`";
const originalText = "What's this?"; const originalText = "What's this?";
let glitchInterval: NodeJS.Timeout; let glitchInterval: NodeJS.Timeout;
let animationFrame: number;
setTimeout(() => { setTimeout(() => {
setGetLostVisible(true); setGetLostVisible(true);
let currentIndex = 0; let currentIndex = 0;
const typeInterval = setInterval(() => { let lastUpdate = 0;
const updateInterval = 80; // ms between updates
const revealAnimation = (timestamp: number) => {
if (timestamp - lastUpdate >= updateInterval) {
if (currentIndex <= originalText.length) { if (currentIndex <= originalText.length) {
let displayText = originalText.substring(0, currentIndex); let displayText = originalText.substring(0, currentIndex);
if (currentIndex < originalText.length) { if (currentIndex < originalText.length) {
@@ -282,17 +287,20 @@ export function LeftBar() {
} }
setGetLostText(displayText); setGetLostText(displayText);
currentIndex++; currentIndex++;
lastUpdate = timestamp;
} else { } else {
clearInterval(typeInterval);
setGetLostText(originalText); setGetLostText(originalText);
// Occasional glitch effect after reveal
glitchInterval = setInterval(() => { glitchInterval = setInterval(() => {
if (Math.random() > 0.9) { if (Math.random() > 0.92) {
let glitched = ""; let glitched = "";
for (let i = 0; i < originalText.length; i++) { for (let i = 0; i < originalText.length; i++) {
if (Math.random() > 0.7) { if (Math.random() > 0.75) {
glitched += glitched +=
glitchChars[Math.floor(Math.random() * glitchChars.length)]; glitchChars[
Math.floor(Math.random() * glitchChars.length)
];
} else { } else {
glitched += originalText[i]; glitched += originalText[i];
} }
@@ -301,11 +309,16 @@ export function LeftBar() {
setTimeout(() => { setTimeout(() => {
setGetLostText(originalText); setGetLostText(originalText);
}, 100); }, 80);
} }
}, 150); }, 200);
return;
} }
}, 140); }
animationFrame = requestAnimationFrame(revealAnimation);
};
animationFrame = requestAnimationFrame(revealAnimation);
}, 500); }, 500);
if (ref) { if (ref) {
@@ -345,11 +358,13 @@ export function LeftBar() {
onCleanup(() => { onCleanup(() => {
ref?.removeEventListener("keydown", handleKeyDown); ref?.removeEventListener("keydown", handleKeyDown);
clearInterval(glitchInterval); clearInterval(glitchInterval);
if (animationFrame) cancelAnimationFrame(animationFrame);
window.removeEventListener("resize", handleResize); window.removeEventListener("resize", handleResize);
}); });
} else { } else {
onCleanup(() => { onCleanup(() => {
clearInterval(glitchInterval); clearInterval(glitchInterval);
if (animationFrame) cancelAnimationFrame(animationFrame);
window.removeEventListener("resize", handleResize); window.removeEventListener("resize", handleResize);
}); });
} }
@@ -586,7 +601,8 @@ export function LeftBar() {
navigate(randomUrl); navigate(randomUrl);
handleLinkClick(); handleLinkClick();
}} }}
class="text-left font-mono" class="text-left font-mono transition-opacity duration-75"
style={{ "will-change": "contents" }}
> >
{getLostText()} {getLostText()}
</button> </button>

View File

@@ -1,12 +1,14 @@
import { Show } from "solid-js"; import { Show, lazy } from "solid-js";
import CardLinks from "./CardLinks"; import CardLinks from "./CardLinks";
import DeletePostButton from "./DeletePostButton";
import { Fire } from "~/components/icons/Fire"; import { Fire } from "~/components/icons/Fire";
import { Post } from "~/db/types"; import { PostCardData } from "~/db/types";
const DeletePostButton = lazy(() => import("./DeletePostButton"));
export interface CardProps { export interface CardProps {
post: Post; post: PostCardData;
privilegeLevel: "anonymous" | "admin" | "user"; privilegeLevel: "anonymous" | "admin" | "user";
index?: number;
} }
export default function Card(props: CardProps) { export default function Card(props: CardProps) {
@@ -27,6 +29,12 @@ export default function Card(props: CardProps) {
<img <img
src={props.post.banner_photo ?? ""} src={props.post.banner_photo ?? ""}
alt={props.post.title.replaceAll("_", " ") + " banner"} alt={props.post.title.replaceAll("_", " ") + " banner"}
loading={
props.index !== undefined && props.index < 3 ? "eager" : "lazy"
}
fetchpriority={props.index === 0 ? "high" : "auto"}
width={1200}
height={630}
class="h-full w-full object-cover" class="h-full w-full object-cover"
/> />
<div class="border-opacity-20 bg-opacity-40 bg-crust border-text absolute bottom-0 w-full border-t px-2 py-4 backdrop-blur-md md:px-6"> <div class="border-opacity-20 bg-opacity-40 bg-crust border-text absolute bottom-0 w-full border-t px-2 py-4 backdrop-blur-md md:px-6">

View File

@@ -1,6 +1,6 @@
import { For, Show, createMemo } from "solid-js"; import { For, Show, createMemo } from "solid-js";
import Card from "./Card"; import Card from "./Card";
import { Post } from "~/db/types"; import { PostCardData } from "~/db/types";
export interface Tag { export interface Tag {
value: string; value: string;
@@ -8,7 +8,7 @@ export interface Tag {
} }
export interface PostSortingProps { export interface PostSortingProps {
posts: Post[]; posts: PostCardData[];
tags: Tag[]; tags: Tag[];
privilegeLevel: "anonymous" | "admin" | "user"; privilegeLevel: "anonymous" | "admin" | "user";
filters?: string; filters?: string;
@@ -133,9 +133,13 @@ export default function PostSorting(props: PostSortingProps) {
} }
> >
<For each={sortedPosts()}> <For each={sortedPosts()}>
{(post) => ( {(post, index) => (
<div class="my-4"> <div class="my-4">
<Card post={post} privilegeLevel={props.privilegeLevel} /> <Card
post={post}
privilegeLevel={props.privilegeLevel}
index={index()}
/>
</div> </div>
)} )}
</For> </For>

View File

@@ -63,6 +63,9 @@ export const model: { [key: string]: string } = {
last_edited_date TEXT last_edited_date TEXT
); );
CREATE INDEX IF NOT EXISTS idx_posts_category ON Post (category); CREATE INDEX IF NOT EXISTS idx_posts_category ON Post (category);
CREATE INDEX IF NOT EXISTS idx_posts_published ON Post (published);
CREATE INDEX IF NOT EXISTS idx_posts_date ON Post (date);
CREATE INDEX IF NOT EXISTS idx_posts_published_date ON Post (published, date);
`, `,
PostLike: ` PostLike: `
CREATE TABLE PostLike CREATE TABLE PostLike
@@ -72,6 +75,7 @@ export const model: { [key: string]: string } = {
post_id INTEGER NOT NULL post_id INTEGER NOT NULL
); );
CREATE UNIQUE INDEX IF NOT EXISTS idx_likes_user_post ON PostLike (user_id, post_id); CREATE UNIQUE INDEX IF NOT EXISTS idx_likes_user_post ON PostLike (user_id, post_id);
CREATE INDEX IF NOT EXISTS idx_likes_post_id ON PostLike (post_id);
`, `,
Comment: ` Comment: `
CREATE TABLE Comment CREATE TABLE Comment

View File

@@ -105,6 +105,21 @@ export interface PostWithCommentsAndLikes {
total_comments: number; total_comments: number;
last_edited_date?: string | null; last_edited_date?: string | null;
} }
export interface PostCardData {
id: number;
category: "blog" | "project";
title: string;
subtitle: string;
banner_photo: string;
date?: string | null;
published: number;
author_id: string;
reads: number;
attachments: string;
total_likes: number;
total_comments: number;
}
export interface PostWithTags { export interface PostWithTags {
id: number; id: number;
category: "blog" | "project"; // this is no longer used category: "blog" | "project"; // this is no longer used

View File

@@ -1,4 +1,4 @@
import { Show } from "solid-js"; import { Show, createSignal, onMount, lazy } from "solid-js";
import { useSearchParams, A, query } from "@solidjs/router"; import { useSearchParams, A, query } from "@solidjs/router";
import { Title } from "@solidjs/meta"; import { Title } from "@solidjs/meta";
import { createAsync } from "@solidjs/router"; import { createAsync } from "@solidjs/router";
@@ -6,11 +6,15 @@ import { getRequestEvent } from "solid-js/web";
import PostSortingSelect from "~/components/blog/PostSortingSelect"; import PostSortingSelect from "~/components/blog/PostSortingSelect";
import TagSelector from "~/components/blog/TagSelector"; import TagSelector from "~/components/blog/TagSelector";
import PostSorting from "~/components/blog/PostSorting"; import PostSorting from "~/components/blog/PostSorting";
import PublishStatusToggle from "~/components/blog/PublishStatusToggle";
import { TerminalSplash } from "~/components/TerminalSplash"; import { TerminalSplash } from "~/components/TerminalSplash";
import { CACHE_CONFIG } from "~/config"; import { CACHE_CONFIG } from "~/config";
const getPosts = query(async () => { const PublishStatusToggle = lazy(() => import("~/components/blog/PublishStatusToggle"));
const POSTS_PER_PAGE = 12;
// Separate query for all tags (needed for TagSelector)
const getAllTags = query(async () => {
"use server"; "use server";
const { ConnectionFactory, getPrivilegeLevel } = const { ConnectionFactory, getPrivilegeLevel } =
await import("~/server/utils"); await import("~/server/utils");
@@ -19,41 +23,11 @@ const getPosts = query(async () => {
const privilegeLevel = await getPrivilegeLevel(event.nativeEvent); const privilegeLevel = await getPrivilegeLevel(event.nativeEvent);
return withCache( return withCache(
`posts-${privilegeLevel}`, `all-tags-${privilegeLevel}`,
CACHE_CONFIG.BLOG_POSTS_LIST_CACHE_TTL_MS, CACHE_CONFIG.BLOG_POSTS_LIST_CACHE_TTL_MS,
async () => { async () => {
const conn = ConnectionFactory(); const conn = ConnectionFactory();
let postsQuery = `
SELECT
p.id,
p.title,
p.subtitle,
p.body,
p.banner_photo,
p.date,
p.published,
p.category,
p.author_id,
p.reads,
p.attachments,
COUNT(DISTINCT pl.user_id) as total_likes,
COUNT(DISTINCT c.id) as total_comments
FROM Post p
LEFT JOIN PostLike pl ON p.id = pl.post_id
LEFT JOIN Comment c ON p.id = c.post_id
`;
if (privilegeLevel !== "admin") {
postsQuery += ` WHERE p.published = TRUE`;
}
postsQuery += ` GROUP BY p.id, p.title, p.subtitle, p.body, p.banner_photo, p.date, p.published, p.category, p.author_id, p.reads, p.attachments`;
postsQuery += ` ORDER BY p.date ASC;`;
const postsResult = await conn.execute(postsQuery);
const posts = postsResult.rows;
const tagsQuery = ` const tagsQuery = `
SELECT t.value, t.post_id SELECT t.value, t.post_id
FROM Tag t FROM Tag t
@@ -71,44 +45,200 @@ const getPosts = query(async () => {
tagMap[key] = (tagMap[key] || 0) + 1; tagMap[key] = (tagMap[key] || 0) + 1;
}); });
return { posts, tags, tagMap, privilegeLevel }; return { tagMap, privilegeLevel };
}
);
}, "all-tags");
const getPosts = query(async (page: number = 1) => {
"use server";
const { ConnectionFactory, getPrivilegeLevel } =
await import("~/server/utils");
const { withCache } = await import("~/server/cache");
const event = getRequestEvent()!;
const privilegeLevel = await getPrivilegeLevel(event.nativeEvent);
return withCache(
`posts-${privilegeLevel}-page-${page}`,
CACHE_CONFIG.BLOG_POSTS_LIST_CACHE_TTL_MS,
async () => {
const conn = ConnectionFactory();
const offset = (page - 1) * POSTS_PER_PAGE;
// Get total count first
let countQuery = `SELECT COUNT(*) as total FROM Post p`;
if (privilegeLevel !== "admin") {
countQuery += ` WHERE p.published = TRUE`;
}
const countResult = await conn.execute(countQuery);
const totalPosts = (countResult.rows[0] as any).total;
let postsQuery = `
SELECT
p.id,
p.title,
p.subtitle,
p.banner_photo,
p.date,
p.published,
p.category,
p.author_id,
p.reads,
p.attachments,
COUNT(DISTINCT pl.user_id) as total_likes,
COUNT(DISTINCT c.id) as total_comments
FROM Post p
LEFT JOIN PostLike pl ON p.id = pl.post_id
LEFT JOIN Comment c ON p.id = c.post_id
`;
if (privilegeLevel !== "admin") {
postsQuery += ` WHERE p.published = TRUE`;
}
postsQuery += ` GROUP BY p.id, p.title, p.subtitle, p.banner_photo, p.date, p.published, p.category, p.author_id, p.reads, p.attachments`;
postsQuery += ` ORDER BY p.date ASC`;
postsQuery += ` LIMIT ${POSTS_PER_PAGE} OFFSET ${offset};`;
const postsResult = await conn.execute(postsQuery);
const posts = postsResult.rows;
// Only fetch tags for the posts we're returning
const postIds = posts.map((p: any) => p.id).join(",");
const tagsQuery = postIds
? `
SELECT t.value, t.post_id
FROM Tag t
WHERE t.post_id IN (${postIds})
ORDER BY t.value ASC
`
: `SELECT t.value, t.post_id FROM Tag t WHERE 1=0`;
const tagsResult = await conn.execute(tagsQuery);
const tags = tagsResult.rows;
return {
posts,
tags,
hasMore: offset + posts.length < totalPosts,
totalPosts
};
} }
); );
}, "posts"); }, "posts");
export default function BlogIndex() { export default function BlogIndex() {
const [searchParams] = useSearchParams(); const [searchParams] = useSearchParams();
const [currentPage, setCurrentPage] = createSignal(1);
const [allPosts, setAllPosts] = createSignal<any[]>([]);
const [allTags, setAllTags] = createSignal<any[]>([]);
const [hasMore, setHasMore] = createSignal(true);
const [isLoading, setIsLoading] = createSignal(false);
let sentinelRef: HTMLDivElement | undefined;
const sort = () => searchParams.sort || "newest"; const sort = () => {
const filters = () => const sortParam = searchParams.sort;
"filter" in searchParams ? searchParams.filter : undefined; return Array.isArray(sortParam) ? sortParam[0] : sortParam || "newest";
const include = () => };
"include" in searchParams ? searchParams.include : undefined; const filters = () => {
const status = () => const filterParam = searchParams.filter;
"status" in searchParams ? searchParams.status : undefined; return filterParam
? Array.isArray(filterParam)
? filterParam[0]
: filterParam
: undefined;
};
const include = () => {
const includeParam = searchParams.include;
return includeParam
? Array.isArray(includeParam)
? includeParam[0]
: includeParam
: undefined;
};
const status = () => {
const statusParam = searchParams.status;
return statusParam
? Array.isArray(statusParam)
? statusParam[0]
: statusParam
: undefined;
};
const data = createAsync(() => getPosts(), { deferStream: true }); // Load initial page and tag data
const initialData = createAsync(() => getPosts(1), { deferStream: true });
const tagsData = createAsync(() => getAllTags(), { deferStream: true });
// Initialize with first page data
const initializeData = () => {
const firstPage = initialData();
if (firstPage) {
setAllPosts(firstPage.posts);
setAllTags(firstPage.tags);
setHasMore(firstPage.hasMore);
}
};
// Load more posts
const loadMorePosts = async () => {
if (isLoading() || !hasMore()) return;
setIsLoading(true);
const nextPage = currentPage() + 1;
try {
const newData = await getPosts(nextPage);
setAllPosts((prev) => [...prev, ...newData.posts]);
setAllTags((prev) => [...prev, ...newData.tags]);
setHasMore(newData.hasMore);
setCurrentPage(nextPage);
} catch (error) {
console.error("Error loading more posts:", error);
} finally {
setIsLoading(false);
}
};
// Set up IntersectionObserver for infinite scroll
onMount(() => {
initializeData();
const observer = new IntersectionObserver(
(entries) => {
if (entries[0]?.isIntersecting) {
loadMorePosts();
}
},
{ rootMargin: "200px" }
);
if (sentinelRef) {
observer.observe(sentinelRef);
}
return () => observer.disconnect();
});
return ( return (
<> <>
<Title>Blog | Michael Freno</Title> <Title>Blog | Michael Freno</Title>
<div class="mx-auto py-16 pb-24"> <div class="mx-auto py-16 pb-24">
<Show when={data()} fallback={<TerminalSplash />}> <Show when={initialData() && tagsData()} fallback={<TerminalSplash />}>
{(loadedData) => (
<>
<div class="flex flex-col items-center gap-4 px-4 md:flex-row md:justify-around"> <div class="flex flex-col items-center gap-4 px-4 md:flex-row md:justify-around">
<PostSortingSelect /> <PostSortingSelect />
<Show when={Object.keys(loadedData().tagMap).length > 0}> <Show
<TagSelector tagMap={loadedData().tagMap} /> when={tagsData() && Object.keys(tagsData()!.tagMap).length > 0}
>
<TagSelector tagMap={tagsData()!.tagMap} />
</Show> </Show>
<Show when={loadedData().privilegeLevel === "admin"}> <Show when={tagsData()?.privilegeLevel === "admin"}>
<PublishStatusToggle /> <PublishStatusToggle />
</Show> </Show>
<Show when={loadedData().privilegeLevel === "admin"}> <Show when={tagsData()?.privilegeLevel === "admin"}>
<div class="mt-2 flex justify-center md:mt-0 md:justify-end"> <div class="mt-2 flex justify-center md:mt-0 md:justify-end">
<A <A
href="/blog/create" href="/blog/create"
@@ -121,23 +251,30 @@ export default function BlogIndex() {
</div> </div>
<Show <Show
when={loadedData().posts.length > 0} when={allPosts().length > 0}
fallback={<div class="pt-12 text-center">No posts yet!</div>} fallback={<div class="pt-12 text-center">No posts yet!</div>}
> >
<div class="mx-auto flex w-11/12 flex-col pt-8"> <div class="mx-auto flex w-11/12 flex-col pt-8">
<PostSorting <PostSorting
posts={loadedData().posts} posts={allPosts()}
tags={loadedData().tags} tags={allTags()}
privilegeLevel={loadedData().privilegeLevel} privilegeLevel={tagsData()!.privilegeLevel}
filters={filters()} filters={filters()}
sort={sort()} sort={sort()}
include={include()} include={include()}
status={status()} status={status()}
/> />
{/* Sentinel element for infinite scroll */}
<Show when={hasMore()}>
<div ref={sentinelRef} class="py-8 text-center">
<Show when={isLoading()}>
<div class="text-lg">Loading more posts...</div>
</Show>
</div>
</Show>
</div> </div>
</Show> </Show>
</>
)}
</Show> </Show>
</div> </div>
</> </>

View File

@@ -65,6 +65,8 @@ export default function Home() {
<div class="aspect-auto w-full overflow-hidden rounded-lg"> <div class="aspect-auto w-full overflow-hidden rounded-lg">
<video <video
src="/flexlove-scrollable.mp4" src="/flexlove-scrollable.mp4"
width={1280}
height={1290}
class="h-full w-full object-cover" class="h-full w-full object-cover"
autoplay autoplay
loop loop
@@ -75,6 +77,8 @@ export default function Home() {
<div class="aspect-auto w-full overflow-hidden rounded-lg"> <div class="aspect-auto w-full overflow-hidden rounded-lg">
<video <video
src="/flexlove-input.mp4" src="/flexlove-input.mp4"
width={1148}
height={140}
class="h-full w-full object-cover" class="h-full w-full object-cover"
autoplay autoplay
loop loop
@@ -85,6 +89,8 @@ export default function Home() {
<div class="aspect-auto w-full overflow-hidden rounded-lg"> <div class="aspect-auto w-full overflow-hidden rounded-lg">
<video <video
src="/flexlove-slider.mp4" src="/flexlove-slider.mp4"
width={1256}
height={134}
class="h-full w-full object-cover" class="h-full w-full object-cover"
autoplay autoplay
loop loop
@@ -118,6 +124,8 @@ export default function Home() {
<div class="aspect-auto w-full overflow-hidden rounded-lg sm:col-span-1"> <div class="aspect-auto w-full overflow-hidden rounded-lg sm:col-span-1">
<video <video
src="/lineage-preview.mp4" src="/lineage-preview.mp4"
width={886}
height={1920}
class="h-full w-full object-cover" class="h-full w-full object-cover"
autoplay autoplay
loop loop
@@ -130,6 +138,8 @@ export default function Home() {
<img <img
src="/lineage-home.png" src="/lineage-home.png"
alt="Life and Lineage Home" alt="Life and Lineage Home"
width={1320}
height={2868}
class="h-full w-full object-cover" class="h-full w-full object-cover"
/> />
</div> </div>
@@ -137,6 +147,8 @@ export default function Home() {
<img <img
src="/lineage-shops.png" src="/lineage-shops.png"
alt="Life and Lineage Shops" alt="Life and Lineage Shops"
width={608}
height={1322}
class="h-full w-full object-cover" class="h-full w-full object-cover"
/> />
</div> </div>