diff --git a/src/components/High/Table.tsx b/src/components/High/Table.tsx index 572e619a..effb0e91 100644 --- a/src/components/High/Table.tsx +++ b/src/components/High/Table.tsx @@ -9,7 +9,7 @@ import { useReactTable, } from "@tanstack/react-table"; import clsx from "clsx"; -import { useEffect, useState } from "react"; +import { useState } from "react"; import { BsArrowDown, BsArrowUp } from "react-icons/bs"; import Button from "../Low/Button"; diff --git a/src/pages/api/sessions/index.ts b/src/pages/api/sessions/index.ts index 68ac3b08..5397a74a 100644 --- a/src/pages/api/sessions/index.ts +++ b/src/pages/api/sessions/index.ts @@ -48,4 +48,9 @@ async function post(req: NextApiRequest, res: NextApiResponse) { await db.collection("sessions").updateOne({ id: session.id }, { $set: session }, { upsert: true }); res.status(200).json({ ok: true }); + const sessions = await db.collection("sessions").find({ user: session.user }, { projection: { id: 1 } }).sort({ date: 1 }).toArray(); + // Delete old sessions + if (sessions.length > 5) { + await db.collection("sessions").deleteOne({ id: { $in: sessions.slice(0, sessions.length - 5).map(x => x.id) } }); + } }