diff --git a/.gitignore b/.gitignore index 758d554..46c281d 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,4 @@ node_modules .venv prisma/dev.db* +logs.txt diff --git a/bun.lockb b/bun.lockb index 0ee2d4f..b367575 100755 Binary files a/bun.lockb and b/bun.lockb differ diff --git a/main.ts b/main.ts index b99d0af..75afe67 100644 --- a/main.ts +++ b/main.ts @@ -2,7 +2,7 @@ import "dotenv/config"; import Datastore from "nedb"; import WebSocket from "ws"; import { createInterface } from "readline"; -import { Channel, Client, Score } from "osu-web.js"; +import { Client, type Channel, type Score } from "osu-web.js"; import { PrismaClient } from "@prisma/client"; const prisma = new PrismaClient(); @@ -196,9 +196,14 @@ async function scrapeChannels() { } async function getStats(elapsed) { + // console.clear(); + const result = await prisma.score.count(); + const users = (await prisma.score.groupBy({ by: ["user_id"] })).length; console.log( - `${result} total scores (prev query: ${Math.round(elapsed / 10) / 100}s)`, + `${result} total scores, ${users} total users, (prev query: ${ + Math.round(elapsed / 10) / 100 + }s)`, ); const result2 = await prisma.$queryRaw` @@ -215,14 +220,10 @@ async function getStats(elapsed) { } } -async function mainLoop() { - while (true) { - const start = performance.now(); - await scrapeChannels(); - const end = performance.now(); - await getStats(end - start); - await sleep(10000); - } +while (true) { + const start = performance.now(); + await scrapeChannels(); + const end = performance.now(); + await getStats(end - start); + await Bun.sleep(10000); } - -mainLoop(); diff --git a/package.json b/package.json index d81f46e..1cb4bb3 100644 --- a/package.json +++ b/package.json @@ -6,6 +6,7 @@ "osu-web.js": "^2.4.0" }, "devDependencies": { + "@types/bun": "^1.1.3", "@types/nedb": "^1.8.16", "@types/ws": "^8.5.10", "prisma": "^5.14.0" diff --git a/prisma/migrations/20240530173352_a/migration.sql b/prisma/migrations/20240530173352_a/migration.sql new file mode 100644 index 0000000..d5bb944 --- /dev/null +++ b/prisma/migrations/20240530173352_a/migration.sql @@ -0,0 +1,5 @@ +-- CreateIndex +CREATE INDEX "Score_user_id_idx" ON "Score"("user_id"); + +-- CreateIndex +CREATE INDEX "Transition_user_id_idx" ON "Transition"("user_id"); diff --git a/prisma/schema.prisma b/prisma/schema.prisma index e25a962..525f50f 100644 --- a/prisma/schema.prisma +++ b/prisma/schema.prisma @@ -49,6 +49,7 @@ model Score { transition_to Transition[] @relation("after") @@unique([user_id, beatmap_id, created_at, score]) + @@index([user_id]) } model Transition { @@ -61,4 +62,5 @@ model Transition { ms_between BigInt @@id([before_id, after_id]) + @@index([user_id]) } diff --git a/tsconfig.json b/tsconfig.json new file mode 100644 index 0000000..97a3262 --- /dev/null +++ b/tsconfig.json @@ -0,0 +1,23 @@ +{ + "compilerOptions": { + "lib": ["ESNext", "DOM"], + "target": "ESNext", + "module": "ESNext", + "moduleDetection": "force", + "jsx": "react-jsx", + "allowJs": true, + + "moduleResolution": "bundler", + "allowImportingTsExtensions": true, + "verbatimModuleSyntax": true, + "noEmit": true, + + "strict": true, + "skipLibCheck": true, + "noFallthroughCasesInSwitch": true, + + "noUnusedLocals": true, + "noUnusedParameters": true, + "noPropertyAccessFromIndexSignature": true + } +}