From 728e8dbf5428ef9bc39d5f7b3205b9d5ac7122f2 Mon Sep 17 00:00:00 2001 From: Nainjasu Date: Sun, 31 Mar 2024 19:04:28 +0000 Subject: [PATCH] restore db clans --- app/util/alerts.tsx | 4 +- packages/server/router/stats/getClanStats.ts | 77 ++++++++++--------- .../server/router/stats/getPlayerRanked.ts | 24 +++--- .../server/router/stats/getPlayerStats.ts | 44 +++++------ packages/server/router/stats/getRankings.ts | 44 ++++++----- 5 files changed, 98 insertions(+), 95 deletions(-) diff --git a/app/util/alerts.tsx b/app/util/alerts.tsx index 778ea960..37cd5d75 100644 --- a/app/util/alerts.tsx +++ b/app/util/alerts.tsx @@ -58,8 +58,8 @@ export const alerts = { ), NEW_BH_WIKI: ( - The Brawlhalla Wiki has officially migrated to its new home at wiki.gg! - Explore the latest updates and resources by visiting{" "} + The Brawlhalla Wiki has officially migrated to its new home at + wiki.gg! Explore the latest updates and resources by visiting{" "} { - // logError( - // `Failed to update clan#${clan.clan_id} in database`, - // e, - // ) - // }), - // // withTimeLog(updateDBPlayerAliases, "updateDBPlayerAliases")( - // // clan.clan.map((member) => ({ - // // playerId: member.brawlhalla_id.toString(), - // // alias: member.name, - // // createdAt: new Date(), - // // public: true, - // // })), - // // { - // // abortSignal: controller.signal, - // // }, - // // ).catch((e) => { - // // logError( - // // `Error updating player aliases for clan#${clan.clan_id}`, - // // e, - // // ) - // // }), - // ]) + // Fire and forget + const fireAndForget = Promise.all([ + withTimeLog(updateDBClanData, "updateDBClanData")( + { + id: clan.clan_id.toString(), + name: clan.clan_name, + created: clan.clan_create_date, + xp: parseInt(clan.clan_xp), + }, + { + abortSignal: controller.signal, + }, + ).catch((e) => { + logError( + `Failed to update clan#${clan.clan_id} in database`, + e, + ) + }), + withTimeLog(updateDBPlayerAliases, "updateDBPlayerAliases")( + clan.clan.map((member) => ({ + playerId: member.brawlhalla_id.toString(), + alias: member.name, + createdAt: new Date(), + public: true, + })), + { + abortSignal: controller.signal, + }, + ).catch((e) => { + logError( + `Error updating player aliases for clan#${clan.clan_id}`, + e, + ) + }), + ]) - // waitForRequestTimeout(fireAndForget, { - // abortController: controller, - // }) + waitForRequestTimeout(fireAndForget, { + abortController: controller, + }) return clan }, "getClanStats"), diff --git a/packages/server/router/stats/getPlayerRanked.ts b/packages/server/router/stats/getPlayerRanked.ts index 76f05813..38649458 100644 --- a/packages/server/router/stats/getPlayerRanked.ts +++ b/packages/server/router/stats/getPlayerRanked.ts @@ -47,19 +47,19 @@ export const getPlayerRanked = publicProcedure // public: true, })) - // // Fire and forget - // const fireAndForget = withTimeLog( - // updateDBPlayerAliases, - // "updateDBPlayerAliases", - // )(aliases, { - // abortSignal: controller.signal, - // }).catch((e) => { - // logError("Error updating player aliases", e) - // }) + // Fire and forget + const fireAndForget = withTimeLog( + updateDBPlayerAliases, + "updateDBPlayerAliases", + )(aliases, { + abortSignal: controller.signal, + }).catch((e) => { + logError("Error updating player aliases", e) + }) - // waitForRequestTimeout(fireAndForget, { - // abortController: controller, - // }) + waitForRequestTimeout(fireAndForget, { + abortController: controller, + }) return ranked }, "getPlayerRanked"), diff --git a/packages/server/router/stats/getPlayerStats.ts b/packages/server/router/stats/getPlayerStats.ts index 35942bfa..247c2336 100644 --- a/packages/server/router/stats/getPlayerStats.ts +++ b/packages/server/router/stats/getPlayerStats.ts @@ -48,29 +48,29 @@ export const getPlayerStats = publicProcedure // }) } - // // Fire and forget - // const fireAndForget = Promise.all([ - // withTimeLog(updateDBPlayerAliases, "updateDBPlayerAliases")( - // [ - // { - // playerId: stats.brawlhalla_id.toString(), - // alias: stats.name, - // createdAt: new Date(), - // public: true, - // }, - // ], - // { - // abortSignal: controller.signal, - // }, - // ).catch((e) => { - // logError("Error updating player aliases", e) - // }), - // updateClanData(), - // ]) + // Fire and forget + const fireAndForget = Promise.all([ + withTimeLog(updateDBPlayerAliases, "updateDBPlayerAliases")( + [ + { + playerId: stats.brawlhalla_id.toString(), + alias: stats.name, + createdAt: new Date(), + public: true, + }, + ], + { + abortSignal: controller.signal, + }, + ).catch((e) => { + logError("Error updating player aliases", e) + }), + updateClanData(), + ]) - // waitForRequestTimeout(fireAndForget, { - // abortController: controller, - // }) + waitForRequestTimeout(fireAndForget, { + abortController: controller, + }) return stats }, "getPlayerStats"), diff --git a/packages/server/router/stats/getRankings.ts b/packages/server/router/stats/getRankings.ts index 5ca0cb47..fbfc7402 100644 --- a/packages/server/router/stats/getRankings.ts +++ b/packages/server/router/stats/getRankings.ts @@ -1,8 +1,10 @@ import { getRankings } from "bhapi" -import { logInfo } from "logger" +import { logError, logInfo } from "logger" import { numericLiteralValidator } from "common/helpers/validators" import { publicProcedure } from "../../trpc" import { rankedRegionValidator } from "bhapi/constants" +import { updateDBPlayerAliases } from "../../mutations/updateDBPlayerAliases" +import { waitForRequestTimeout } from "../../helpers/waitForRequestTimeout" import { withTimeLog } from "../../helpers/withTimeLog" import { z } from "zod" @@ -19,7 +21,7 @@ export const get1v1Rankings = publicProcedure // const { region, page, name } = req.input logInfo("get1v1Rankings", req.input) - // const controller = new AbortController() + const controller = new AbortController() const rankings = await withTimeLog( getRankings, @@ -27,26 +29,26 @@ export const get1v1Rankings = publicProcedure // )("1v1", region, page, name) // Fire and forget - // const fireAndForget = withTimeLog( - // updateDBPlayerAliases, - // "updateDBPlayerAliases", - // )( - // rankings.map((player) => ({ - // playerId: player.brawlhalla_id.toString(), - // alias: player.name, - // createdAt: new Date(), - // public: true, - // })), - // { - // abortSignal: controller.signal, - // }, - // ).catch((e) => { - // logError("Error updating player aliases", e) - // }) + const fireAndForget = withTimeLog( + updateDBPlayerAliases, + "updateDBPlayerAliases", + )( + rankings.map((player) => ({ + playerId: player.brawlhalla_id.toString(), + alias: player.name, + createdAt: new Date(), + public: true, + })), + { + abortSignal: controller.signal, + }, + ).catch((e) => { + logError("Error updating player aliases", e) + }) - // waitForRequestTimeout(fireAndForget, { - // abortController: controller, - // }) + waitForRequestTimeout(fireAndForget, { + abortController: controller, + }) return rankings }, "get1v1Rankings"),