From d5225374230906efecfb8fd34b7950411391f23d Mon Sep 17 00:00:00 2001 From: Michael Zhang Date: Fri, 31 May 2024 20:37:21 -0500 Subject: [PATCH] update --- .gitignore | 1 + bun.lockb | Bin 9090 -> 9852 bytes main.ts | 25 +++++++++--------- package.json | 1 + .../migrations/20240530173352_a/migration.sql | 5 ++++ prisma/schema.prisma | 2 ++ tsconfig.json | 23 ++++++++++++++++ 7 files changed, 45 insertions(+), 12 deletions(-) create mode 100644 prisma/migrations/20240530173352_a/migration.sql create mode 100644 tsconfig.json 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 0ee2d4f690b4d09a797792be54f00fc23777d97c..b367575848f8a1b5e5feaea74d78eaa0353e78aa 100755 GIT binary patch delta 1688 zcmd56ZA@EL^xoH3`sg-GVO#s!Qo_uJd_4--jXGyz2)YkZlLfXc&JETEJJ*5~g-Qa9 z><5t{;E9eb3%HM{aWa>I(Xve350{950~ZsWgk&zUW;2oK51J_RoY(iJiP?Woa?kg@ z_ndpqx!q6y`OJWlZ|eT^R)50Ua5{e7As?Qd8QEJsEcG`Ueq6lW9j@AQ`R+!hf;_k< zr_(E^gnw`mvS!A*BEdjCX(u%~{Bj`F+{9Qo6bXex(Ux)4uR^~gp&+@j1ZONArtd7_&T&inStRHl(wtSc`NN=^CUHn!FA- z(!uk_)P=S*##W<@L8<{DQ3IYseL8sg<&3Gc{42XWNB?NQ+c49Ud1nLs#<%m$;1m43 z8DfaPf;eIeBoSAF&*10n5JNlxal}iIL|h0y(a&2UhWJB>BVL50=r>D4!+{Q4Rjvj(RmX=Rp62HZkVO12_)LBtfS73u zcm&CM3RCjpx%jkRlGz%#POeIl)DB0~PQKgtTb832*Mzb|LQSzsH6V1UT;3ClCqssjs16;AJ zP{fRl6{atkIyp-z^p_xu*!#=d-+VE7B4_Zui*t#o8aTJHC>mUo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N1|zEHd4_N0y9o0bD?55p=f20Q$L`Exu0B^yt;@?)yRlmPUDb97 YI~t6qwC!p+Ogbu4%Z|ZZSlKoD2P-<;`~Uy| 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 + } +}