Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Restore db clans #105

Merged
merged 1 commit into from
Apr 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions app/util/alerts.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ export const alerts = {
),
NEW_BH_WIKI: (
<span>
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{" "}
<AppLink
href="https://brawlhalla.wiki.gg"
target="_blank"
Expand Down
77 changes: 39 additions & 38 deletions packages/server/router/stats/getClanStats.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { logError, logInfo } from "logger"
import { numericLiteralValidator } from "common/helpers/validators"
import { publicProcedure } from "../../trpc"
import { updateDBClanData } from "../../mutations/updateDBClanData"
import { updateDBPlayerAliases } from "../../mutations/updateDBPlayerAliases"
import { waitForRequestTimeout } from "../../helpers/waitForRequestTimeout"
import { withTimeLog } from "../../helpers/withTimeLog"
import { z } from "zod"
Expand All @@ -22,45 +23,45 @@ export const getClanStats = publicProcedure //

const clan = await withTimeLog(getClan, "BHAPI:clanStats")(clanId)

// // 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,
// // )
// // }),
// ])
// 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"),
Expand Down
24 changes: 12 additions & 12 deletions packages/server/router/stats/getPlayerRanked.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand Down
44 changes: 22 additions & 22 deletions packages/server/router/stats/getPlayerStats.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand Down
44 changes: 23 additions & 21 deletions packages/server/router/stats/getRankings.ts
Original file line number Diff line number Diff line change
@@ -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"

Expand All @@ -19,34 +21,34 @@ 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,
"BHAPI:rankings1v1",
)("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"),
Expand Down
Loading