blog-likes.ts

src/utils/blog-likes.ts
import 'server-only'
import { prisma } from '@/utils/prisma'
import { kv, likeCountKey, likesKey } from '@/utils/kv'
const TTL_SECONDS = 60 * 60 * 24 // 24h
// Clears the cached like count and likers set. Use after a like/unlike write.
export async function invalidateLike(id: number): Promise<void> {
const p = kv.pipeline()
p.del(likeCountKey(id))
p.del(likesKey(id))
await p.exec()
}
export async function getLikeCountFromDb(id: number): Promise<number> {
return prisma.blogLike.count({ where: { post_id: id } })
}
export async function getLikeCount(id: number): Promise<number> {
const cached = await kv.get<number | string>(likeCountKey(id))

Showing the first 20 lines.

Get full code

Support

Talk to the developers of this project to learn more

We have been building professional websites for big clients for over 15 years. Gallop templates and blocks is our best foundation for SEO websites and web apps.

© 2026 Web Plant Media, LLC