move logging to debug and make mappers clickable on the score
All checks were successful
Deploy SSR / deploy (push) Successful in 1m13s
All checks were successful
Deploy SSR / deploy (push) Successful in 1m13s
This commit is contained in:
@ -16,7 +16,7 @@ export default class DataFetcher {
|
||||
* @param data the data to log
|
||||
*/
|
||||
public log(data: unknown) {
|
||||
console.log(`[${this.name}]: ${data}`);
|
||||
console.debug(`[${this.name}]: ${data}`);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1,6 +1,7 @@
|
||||
import BeatSaverMap from "@/common/database/types/beatsaver-map";
|
||||
import { db } from "../../database/database";
|
||||
import DataFetcher from "../data-fetcher";
|
||||
import { BeatSaverMap } from "../types/beatsaver/beatsaver-map";
|
||||
import { BeatSaverMap as BSMap } from "../types/beatsaver/beatsaver-map";
|
||||
|
||||
const API_BASE = "https://api.beatsaver.com";
|
||||
const LOOKUP_MAP_BY_HASH_ENDPOINT = `${API_BASE}/maps/hash/:query`;
|
||||
@ -17,17 +18,18 @@ class BeatSaverFetcher extends DataFetcher {
|
||||
* @param useProxy whether to use the proxy or not
|
||||
* @returns the map that match the query, or undefined if no map were found
|
||||
*/
|
||||
async getMapBsr(query: string, useProxy = true): Promise<string | undefined> {
|
||||
this.log(`Looking up the bsr for map hash ${query}...`);
|
||||
async lookupMap(query: string, useProxy = true): Promise<BeatSaverMap | undefined> {
|
||||
const before = performance.now();
|
||||
this.log(`Looking up map "${query}"...`);
|
||||
|
||||
const map = await db.beatSaverMaps.get(query);
|
||||
let map = await db.beatSaverMaps.get(query);
|
||||
// The map is cached
|
||||
if (map != undefined) {
|
||||
this.log(`Found cached bsr ${map.bsr} for map hash ${query}`);
|
||||
return map.bsr;
|
||||
this.log(`Found cached map "${query}" in ${(performance.now() - before).toFixed(2)}ms`);
|
||||
return map;
|
||||
}
|
||||
|
||||
const response = await this.fetch<BeatSaverMap>(useProxy, LOOKUP_MAP_BY_HASH_ENDPOINT.replace(":query", query));
|
||||
const response = await this.fetch<BSMap>(useProxy, LOOKUP_MAP_BY_HASH_ENDPOINT.replace(":query", query));
|
||||
// Map not found
|
||||
if (response == undefined) {
|
||||
return undefined;
|
||||
@ -42,9 +44,11 @@ class BeatSaverFetcher extends DataFetcher {
|
||||
await db.beatSaverMaps.add({
|
||||
hash: query,
|
||||
bsr: bsr,
|
||||
fullData: response,
|
||||
});
|
||||
this.log(`Looked up bsr ${bsr} for map hash ${query}`);
|
||||
return bsr;
|
||||
map = await db.beatSaverMaps.get(query);
|
||||
this.log(`Found map "${query}" in ${(performance.now() - before).toFixed(2)}ms`);
|
||||
return map;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -22,6 +22,7 @@ class ScoreSaberFetcher extends DataFetcher {
|
||||
* @returns the players that match the query, or undefined if no players were found
|
||||
*/
|
||||
async searchPlayers(query: string, useProxy = true): Promise<ScoreSaberPlayerSearch | undefined> {
|
||||
const before = performance.now();
|
||||
this.log(`Searching for players matching "${query}"...`);
|
||||
const results = await this.fetch<ScoreSaberPlayerSearch>(
|
||||
useProxy,
|
||||
@ -34,6 +35,7 @@ class ScoreSaberFetcher extends DataFetcher {
|
||||
return undefined;
|
||||
}
|
||||
results.players.sort((a, b) => a.rank - b.rank);
|
||||
this.log(`Found ${results.players.length} players in ${(performance.now() - before).toFixed(2)}ms`);
|
||||
return results;
|
||||
}
|
||||
|
||||
@ -45,8 +47,14 @@ class ScoreSaberFetcher extends DataFetcher {
|
||||
* @returns the player that matches the ID, or undefined
|
||||
*/
|
||||
async lookupPlayer(playerId: string, useProxy = true): Promise<ScoreSaberPlayer | undefined> {
|
||||
const before = performance.now();
|
||||
this.log(`Looking up player "${playerId}"...`);
|
||||
return await this.fetch<ScoreSaberPlayer>(useProxy, LOOKUP_PLAYER_ENDPOINT.replace(":id", playerId));
|
||||
const response = await this.fetch<ScoreSaberPlayer>(useProxy, LOOKUP_PLAYER_ENDPOINT.replace(":id", playerId));
|
||||
if (response === undefined) {
|
||||
return undefined;
|
||||
}
|
||||
this.log(`Found player "${playerId}" in ${(performance.now() - before).toFixed(2)}ms`);
|
||||
return response;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -64,14 +72,20 @@ class ScoreSaberFetcher extends DataFetcher {
|
||||
page: number,
|
||||
useProxy = true
|
||||
): Promise<ScoreSaberPlayerScoresPage | undefined> {
|
||||
const before = performance.now();
|
||||
this.log(`Looking up scores for player "${playerId}", sort "${sort}", page "${page}"...`);
|
||||
return await this.fetch<ScoreSaberPlayerScoresPage>(
|
||||
const response = await this.fetch<ScoreSaberPlayerScoresPage>(
|
||||
useProxy,
|
||||
LOOKUP_PLAYER_SCORES_ENDPOINT.replace(":id", playerId)
|
||||
.replace(":limit", 8 + "")
|
||||
.replace(":sort", sort)
|
||||
.replace(":page", page.toString())
|
||||
);
|
||||
if (response === undefined) {
|
||||
return undefined;
|
||||
}
|
||||
this.log(`Found scores for player "${playerId}" in ${(performance.now() - before).toFixed(2)}ms`);
|
||||
return response;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,3 +1,4 @@
|
||||
import { BeatSaverMap as BSMap } from "@/common/data-fetcher/types/beatsaver/beatsaver-map";
|
||||
import { Entity } from "dexie";
|
||||
import Database from "../database";
|
||||
|
||||
@ -14,4 +15,9 @@ export default class BeatSaverMap extends Entity<Database> {
|
||||
* The bsr code for the map.
|
||||
*/
|
||||
bsr!: string;
|
||||
|
||||
/**
|
||||
* The full data for the map.
|
||||
*/
|
||||
fullData!: BSMap;
|
||||
}
|
||||
|
Reference in New Issue
Block a user