Merge pull request #53 from atridadl/dev

3.1.1
🚧 Moved to a global cache under the hood
🚧 Updated docs to align with this
🚧 Stopped caching on Vote page... too write heavy to justify
This commit is contained in:
Atridad Lahiji 2023-10-03 17:15:34 -06:00 committed by GitHub
commit da8890cce1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 9 additions and 41 deletions

View file

@ -11,7 +11,7 @@ A scrum poker tool that helps agile teams plan their sprints in real-time.
- Real-time pub/sub: Ably
- ORM: Drizzle ORM
- Database: Turso (libSQL)
- Cache: Redis
- Cache: Upstash (Redis)
## Versioning

View file

@ -4,7 +4,6 @@ export const EventTypes = {
ROOM_LIST_UPDATE: "room.list.update",
ROOM_UPDATE: "room.update",
VOTE_UPDATE: "vote.update",
STATS_UPDATE: "stats.update",
} as const;
export type EventType = BetterEnum<typeof EventTypes>;

View file

@ -150,8 +150,6 @@ export async function PUT(
}
await db.delete(votes).where(eq(votes.roomId, params.roomId));
await invalidateCache(`kv_votes_${params.roomId}`);
}
const newRoom = await db

View file

@ -1,6 +1,5 @@
import { type NextRequest, NextResponse } from "next/server";
import { invalidateCache } from "@/_lib/redis";
import { db } from "@/_lib/db";
import { votes } from "@/_lib/schema";
import { createId } from "@paralleldrive/cuid2";
@ -47,20 +46,12 @@ export async function PUT(
const success = upsertResult.rowsAffected > 0;
if (success) {
await invalidateCache(`kv_votes_${params.roomId}`);
await publishToChannel(
`${params.roomId}`,
EventTypes.VOTE_UPDATE,
reqBody.value
);
await publishToChannel(
`stats`,
EventTypes.STATS_UPDATE,
JSON.stringify(success)
);
return NextResponse.json(upsertResult, {
status: 200,
statusText: "SUCCESS",

View file

@ -1,6 +1,5 @@
import { NextResponse } from "next/server";
import { fetchCache, setCache } from "@/_lib/redis";
import { db } from "@/_lib/db";
import { votes } from "@/_lib/schema";
import { eq } from "drizzle-orm";
@ -18,31 +17,12 @@ export async function GET(
});
}
const cachedResult = await fetchCache<
{
id: string;
value: string;
created_at: Date;
userId: string;
roomId: string;
}[]
>(`kv_votes_${params.roomId}`);
const votesByRoomId = await db.query.votes.findMany({
where: eq(votes.roomId, params.roomId),
});
if (cachedResult) {
return NextResponse.json(cachedResult, {
status: 200,
statusText: "SUCCESS!",
});
} else {
const votesByRoomId = await db.query.votes.findMany({
where: eq(votes.roomId, params.roomId),
});
await setCache(`kv_votes_${params.roomId}`, votesByRoomId);
return NextResponse.json(votesByRoomId, {
status: 200,
statusText: "SUCCESS!",
});
}
return NextResponse.json(votesByRoomId, {
status: 200,
statusText: "SUCCESS!",
});
}

View file

@ -1,6 +1,6 @@
{
"name": "sprintpadawan",
"version": "3.1.0",
"version": "3.1.1",
"description": "Plan. Sprint. Repeat.",
"private": true,
"scripts": {