Skip to content

Commit

Permalink
Improve cache busting via Refresh button (WoWAnalyzer#6756)
Browse files Browse the repository at this point in the history
* use `cache` param instead of query param to skip cache

* support setting specific partitions for zones when loading character
rankings

this fixes an issue with character parses for awakened raids, which do
not include the awakened ranks in the "All" partition that is selected
by default

* changelog entry
  • Loading branch information
emallson committed May 3, 2024
1 parent ebdd068 commit a28fe3e
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 22 deletions.
1 change: 1 addition & 0 deletions src/CHANGELOG.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import SpellLink from 'interface/SpellLink';

// prettier-ignore
export default [
change(date(2024, 5, 3), 'Improve behavior of "Refresh" button', emallson),
change(date(2024, 5, 3), 'Second pass at cleaning up dead code using knip', Putro),
change(date(2024, 5, 2), 'Fix issue with boss detection', emallson),
change(date(2024, 4, 26), 'Actually fix friendly/enemy determination', emallson),
Expand Down
19 changes: 12 additions & 7 deletions src/common/fetchWclApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,12 +89,12 @@ export async function toJson(response: string | Response) {
}
}

async function rawFetchWcl(endpoint: string, queryParams: QueryParams) {
async function rawFetchWcl(endpoint: string, queryParams: QueryParams, noCache: boolean = false) {
if (import.meta.env.MODE === 'test') {
throw new Error('Unable to query WCL during test');
}
const url = makeWclApiUrl(endpoint, queryParams);
const response = await fetch(url);
const response = await fetch(url, { cache: noCache ? 'reload' : 'default' });

if (Object.values(HTTP_CODES.CLOUDFLARE).includes(response.status)) {
throw new ApiDownError(
Expand Down Expand Up @@ -133,6 +133,7 @@ export default function fetchWcl<T extends WCLResponseJSON>(
endpoint: string,
queryParams: QueryParams,
options?: WclOptions,
noCache: boolean = false,
): Promise<T> {
options = !options ? defaultOptions : { ...defaultOptions, ...options };

Expand All @@ -143,7 +144,7 @@ export default function fetchWcl<T extends WCLResponseJSON>(
reject(new Error('Request timed out, probably due to an issue on our side. Try again.'));
}, options!.timeout);

rawFetchWcl(endpoint, queryParams)
rawFetchWcl(endpoint, queryParams, noCache)
.then((results) => {
clearTimeout(timeoutTimer);
if (timedOut) {
Expand All @@ -162,10 +163,14 @@ export default function fetchWcl<T extends WCLResponseJSON>(
}

function rawFetchFights(code: string, refresh = false, translate = true) {
return fetchWcl<WCLFightsResponse>(`report/fights/${code}`, {
_: refresh ? Number(new Date()) : undefined,
translate: translate ? true : undefined, // so long as we don't have the entire site localized, it's better to have 1 consistent language
});
return fetchWcl<WCLFightsResponse>(
`report/fights/${code}`,
{
translate: translate ? true : undefined, // so long as we don't have the entire site localized, it's better to have 1 consistent language
},
undefined,
refresh,
);
}
export async function fetchFights(code: string, refresh = false) {
// This deals with a bunch of bugs in the fights API so implementers don't have to
Expand Down
4 changes: 4 additions & 0 deletions src/game/ZONES.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,15 @@ export interface Zone {
frozen?: boolean;
encounters: Encounter[];
usePtrTooltips?: boolean;
partition?: number;
}

const ZONES: Zone[] = [
{
id: 31,
name: 'Vault of the Incarnates',
frozen: false,
partition: 4,
encounters: [
vaultOfTheIncarnates.bosses.Eranog,
vaultOfTheIncarnates.bosses.Terros,
Expand Down Expand Up @@ -58,6 +60,7 @@ const ZONES: Zone[] = [
id: 33,
name: 'Aberrus, the Shadowed Crucible',
frozen: false,
partition: 6,
encounters: [
aberrus.bosses.Kazzara,
aberrus.bosses.AmalgamationChamber,
Expand Down Expand Up @@ -91,6 +94,7 @@ const ZONES: Zone[] = [
id: 35,
name: "Amirdrassil, the Dream's Hope",
frozen: false,
partition: 3,
encounters: [
amirdrassil.bosses.Gnarlroot,
amirdrassil.bosses.Igira,
Expand Down
24 changes: 9 additions & 15 deletions src/interface/CharacterParses.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -313,18 +313,12 @@ class CharacterParses extends Component<CharacterParsesProps, CharacterParsesSta

const data = await response.json();

if (!data.thumbnail) {
this.setState({
isLoading: false,
error: ERRORS.UNEXPECTED,
errorMessage: 'Corrupt Battle.net API response received.',
});
return;
}
const avatarUrl = data.thumbnail.startsWith('https')
? data.thumbnail
: `https://render-${this.props.region}.worldofwarcraft.com/character/${data.thumbnail}`;
const imageUrl = avatarUrl.replace('avatar.jpg', 'main.jpg');
const avatarUrl = data.thumbnail
? data.thumbnail.startsWith('https')
? data.thumbnail
: `https://render-${this.props.region}.worldofwarcraft.com/character/${data.thumbnail}`
: undefined;
const imageUrl = avatarUrl?.replace('avatar.jpg', 'main.jpg');
const role = data.role;
const metric = role === 'HEALING' ? 'hps' : 'dps';
this.setState(
Expand Down Expand Up @@ -389,10 +383,10 @@ class CharacterParses extends Component<CharacterParsesProps, CharacterParsesSta
metric: this.state.metric,
zone: this.state.activeZoneID,
timeframe: 'historical',
_: refresh ? Number(new Date()) : undefined,
// Always refresh since requiring a manual refresh is unclear and unfriendly to users and they cache hits are low anyway
// _: +new Date(), // disabled due to Uldir raid release hitting cap all the time
partition: this.zones.find((z) => z.id === this.state.activeZoneID)?.partition ?? -1,
},
undefined,
refresh,
)
.then((rawParses) => {
if (rawParses.length === 0) {
Expand Down

0 comments on commit a28fe3e

Please sign in to comment.