update
This commit is contained in:
parent
d9eefa17d4
commit
33187f5066
3 changed files with 27 additions and 16 deletions
1
data/scores.db
Normal file
1
data/scores.db
Normal file
|
@ -0,0 +1 @@
|
||||||
|
{"$$indexCreated":{"fieldName":"key","unique":true,"sparse":false}}
|
0
data/transitions.db
Normal file
0
data/transitions.db
Normal file
42
main.ts
42
main.ts
|
@ -8,19 +8,6 @@ const prisma = new PrismaClient();
|
||||||
|
|
||||||
const redirectUri = "http://localhost:3000/auth/callback";
|
const redirectUri = "http://localhost:3000/auth/callback";
|
||||||
|
|
||||||
const db = {
|
|
||||||
scores: new Datastore({ filename: "data/scores.db", autoload: true }),
|
|
||||||
transitions: new Datastore({
|
|
||||||
filename: "data/transitions.db",
|
|
||||||
autoload: true,
|
|
||||||
}),
|
|
||||||
};
|
|
||||||
|
|
||||||
db.scores.ensureIndex({ fieldName: "key", unique: true });
|
|
||||||
db.scores.persistence.setAutocompactionInterval(5000);
|
|
||||||
|
|
||||||
// await new Promise((resolve) => db.loadDatabase(resolve));
|
|
||||||
|
|
||||||
async function getUserToken() {
|
async function getUserToken() {
|
||||||
const rlInterface = createInterface({
|
const rlInterface = createInterface({
|
||||||
input: process.stdin,
|
input: process.stdin,
|
||||||
|
@ -200,17 +187,40 @@ async function scrapeSingle(channelId) {
|
||||||
|
|
||||||
async function scrapeChannels() {
|
async function scrapeChannels() {
|
||||||
const channels: Channel[] = await fetchApi("/chat/channels");
|
const channels: Channel[] = await fetchApi("/chat/channels");
|
||||||
// // biome-ignore lint/style/noNonNullAssertion: <explanation>
|
|
||||||
// const osuChannel = channels.find((channel) => channel.name === "#osu")!;
|
if (!Array.isArray(channels)) return;
|
||||||
// const { channel_id: osuChannelId } = osuChannel;
|
|
||||||
await Promise.all(
|
await Promise.all(
|
||||||
channels.map((channel) => scrapeSingle(channel.channel_id)),
|
channels.map((channel) => scrapeSingle(channel.channel_id)),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function getStats(elapsed) {
|
||||||
|
const result = await prisma.score.count();
|
||||||
|
console.log(
|
||||||
|
`${result} total scores (prev query: ${Math.round(elapsed / 10) / 100}s)`,
|
||||||
|
);
|
||||||
|
|
||||||
|
const result2 = await prisma.$queryRaw`
|
||||||
|
SELECT
|
||||||
|
beatmapset_id, artist, title, COUNT(*) as count
|
||||||
|
FROM Score
|
||||||
|
JOIN BeatmapSet ON Score.beatmapset_id = BeatmapSet.id
|
||||||
|
GROUP BY beatmapset_id
|
||||||
|
ORDER BY count DESC
|
||||||
|
LIMIT 5;
|
||||||
|
`;
|
||||||
|
for (const row of result2) {
|
||||||
|
console.log(` ${row.count}\t${row.artist} - ${row.title}`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
async function mainLoop() {
|
async function mainLoop() {
|
||||||
while (true) {
|
while (true) {
|
||||||
|
const start = performance.now();
|
||||||
await scrapeChannels();
|
await scrapeChannels();
|
||||||
|
const end = performance.now();
|
||||||
|
await getStats(end - start);
|
||||||
await sleep(10000);
|
await sleep(10000);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue