From 7efe7e05399838f43187bd9799d21b1a9f0c0241 Mon Sep 17 00:00:00 2001 From: emallson Date: Wed, 24 Jul 2024 18:48:33 -0400 Subject: [PATCH] enable event limiting / pagination via WCL's built-in event count mechanism --- src/route/wcl/events.ts | 15 +++++++++++++-- src/wcl/api.ts | 6 ++++-- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/src/route/wcl/events.ts b/src/route/wcl/events.ts index 2e174e9..2b00e47 100644 --- a/src/route/wcl/events.ts +++ b/src/route/wcl/events.ts @@ -2,8 +2,10 @@ import * as api from "../../wcl/api"; import { gql } from "graphql-request"; import { ReportParams, camelCase, compress, wrapEndpoint } from "./common"; +const EVENT_LIMIT = 20000; + // TODO: migrate useAbilityIDs to true. -// requires frontend changes, but means we no longer need to compress the event response (probably) +// requires frontend changes, but is more efficient const eventQuery = gql` query getEvents( $code: String! @@ -12,6 +14,7 @@ const eventQuery = gql` $endTime: Float! $playerId: Int $filter: String + $limit: Int! ) { reportData { report(code: $code) { @@ -23,6 +26,7 @@ const eventQuery = gql` filterExpression: $filter includeResources: true useAbilityIDs: false + limit: $limit ) { data nextPageTimestamp @@ -67,6 +71,7 @@ const events = wrapEndpoint( endTime: number; playerId?: number; filter?: string; + limit: number; } >(eventQuery, { code: req.params.code, @@ -75,6 +80,7 @@ const events = wrapEndpoint( endTime: Number(req.query.end), playerId: req.query.actorid ? Number(req.query.actorid) : undefined, filter: req.query.filter, + limit: EVENT_LIMIT, }); const { data: events, nextPageTimestamp } = rawData.reportData.report.events; @@ -90,7 +96,10 @@ const events = wrapEndpoint( ); export default events; -export const eventsByType = wrapEndpoint( +export const eventsByType = wrapEndpoint< + EventsQuery, + ReportParams & { type: string } +>( "/i/v1/report/events/:type/:code", "wcl-events", async (req) => { @@ -104,6 +113,7 @@ export const eventsByType = wrapEndpoint(eventQuery, { type: req.params.type ? camelCase(req.params.type) : undefined, @@ -113,6 +123,7 @@ export const eventsByType = wrapEndpoint { const basicAuth = Buffer.from( `${process.env.WCL_CLIENT_ID}:${process.env.WCL_CLIENT_SECRET}`, ).toString("base64"); const response = await axios.postForm( - "https://www.warcraftlogs.com/oauth/token", + `${HOST}/oauth/token`, { grant_type: "client_credentials", }, @@ -37,7 +39,7 @@ export async function query( ): Promise { let token = await getToken(); const run = () => - request("https://www.warcraftlogs.com/api/v2/client", gql, variables, { + request(`${HOST}/api/v2/client`, gql, variables, { Authorization: `Bearer ${token}`, "Content-Type": "application/json", "Accept-Encoding": "deflate,gzip",