From ffe45c921800000230ba18cae4dc610a699c2796 Mon Sep 17 00:00:00 2001 From: Oowazu Nonowazu Date: Sun, 13 Dec 2020 01:23:05 -0600 Subject: [PATCH] Save a ton of bandwidth by using a rudimentary cache --- src/Action.js | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/Action.js b/src/Action.js index 4fcf29b..4c8d000 100644 --- a/src/Action.js +++ b/src/Action.js @@ -53,16 +53,25 @@ const ogcdOverrides = new Set([ 114 //bard MB ]) +const actionMap = new Map() + export default function Action({ actionId, additionalClasses }) { const [apiData, setApiData] = React.useState() React.useEffect(() => { + const mapData = actionMap.get(actionId) + if (mapData != null) { + setApiData(mapData) + return + } + let current = true void (async () => { - const data = await (await fetch(`https://xivapi.com/Action/${actionId}`, { + const data = await (await fetch(`https://xivapi.com/Action/${actionId}?colums=Icon,Name,ActionCategoryTargetID`, { mode: "cors" })).json() if (current) { + actionMap.set(actionId, data) setApiData(data) } })() @@ -80,7 +89,7 @@ export default function Action({ actionId, additionalClasses }) {