XFE Git
XFE Studio Git
Git 首页 全局搜索
XFE 主站 文档 NuGet

SpaceNinjaServer

A simple server for a small space ninja game

公开
关注 0 Fork 1 Star 0
返回提交历史

XFEstudio/SpaceNinjaServer

chore(webui): cache inventory data to avoid re-requesting it (#3272)

Reviewed-on: https://onlyg.it/OpenWF/SpaceNinjaServer/pulls/3272 Co-authored-by: Sainan <63328889+Sainan@users.noreply.github.com> Co-committed-by: Sainan <63328889+Sainan@users.noreply.github.com>

07c7baff
Sainan <63328889+Sainan@users.noreply.github.com>
提交于

代码差异

1 个文件 +51 -36
Modified static/webui/script.js +51 -36
@@ -750,10 +750,31 @@ fetchItemList();
750 750
751 751 const accountCheats = document.querySelectorAll("#account-cheats input[id]");
752 752
753 let inventory_data;
754 // Assumes that caller revalidates authz
755 function getInventoryData() {
756 return new Promise((resolve, reject) => {
757 if (inventory_data) {
758 resolve(inventory_data);
759 } else {
760 $.get("/api/inventory.php?" + window.authz + "&xpBasedLevelCapDisabled=1&ignoreBuildLabel=1")
761 .done(data => {
762 inventory_data = data;
763 resolve(inventory_data);
764 })
765 .fail(reject);
766 }
767 });
768 }
769
753 770 // Assumes that caller revalidates authz
754 771 function updateInventory() {
755 const req = $.get("/api/inventory.php?" + window.authz + "&xpBasedLevelCapDisabled=1&ignoreBuildLabel=1");
756 req.done(data => {
772 inventory_data = undefined;
773 translateInventoryDataToDom();
774 }
775
776 function translateInventoryDataToDom() {
777 getInventoryData().then(data => {
757 778 window.itemListPromise.then(itemMap => {
758 779 window.didInitialInventoryUpdate = true;
759 780 window.guildId = data?.GuildId?.$oid;
@@ -2696,8 +2717,7 @@ function addMissingEvolutionProgress() {
2696 2717
2697 2718 function maxRankAllEvolutions() {
2698 2719 revalidateAuthz().then(() => {
2699 const req = $.get("/api/inventory.php?" + window.authz + "&xpBasedLevelCapDisabled=1&ignoreBuildLabel=1");
2700 req.done(data => {
2720 getInventoryData().then(data => {
2701 2721 const requests = [];
2702 2722
2703 2723 data.EvolutionProgress.forEach(item => {
@@ -2722,8 +2742,7 @@ function maxRankAllEvolutions() {
2722 2742
2723 2743 function maxRankAllEquipment(categories) {
2724 2744 revalidateAuthz().then(() => {
2725 const req = $.get("/api/inventory.php?" + window.authz + "&xpBasedLevelCapDisabled=1&ignoreBuildLabel=1");
2726 req.done(data => {
2745 getInventoryData().then(data => {
2727 2746 window.itemListPromise.then(itemMap => {
2728 2747 const batchData = {};
2729 2748
@@ -3291,35 +3310,33 @@ single.getRoute("/webui/cheats").on("beforeload", function () {
3291 3310
3292 3311 function doUnlockAllFocusSchools() {
3293 3312 revalidateAuthz().then(() => {
3294 $.get("/api/inventory.php?" + window.authz + "&xpBasedLevelCapDisabled=1&ignoreBuildLabel=1").done(
3295 async data => {
3296 const missingFocusUpgrades = {
3297 "/Lotus/Upgrades/Focus/Attack/AttackFocusAbility": true,
3298 "/Lotus/Upgrades/Focus/Tactic/TacticFocusAbility": true,
3299 "/Lotus/Upgrades/Focus/Ward/WardFocusAbility": true,
3300 "/Lotus/Upgrades/Focus/Defense/DefenseFocusAbility": true,
3301 "/Lotus/Upgrades/Focus/Power/PowerFocusAbility": true
3302 };
3303 if (data.FocusUpgrades) {
3304 for (const focusUpgrade of data.FocusUpgrades) {
3305 if (focusUpgrade.ItemType in missingFocusUpgrades) {
3306 delete missingFocusUpgrades[focusUpgrade.ItemType];
3307 }
3313 getInventoryData().then(async data => {
3314 const missingFocusUpgrades = {
3315 "/Lotus/Upgrades/Focus/Attack/AttackFocusAbility": true,
3316 "/Lotus/Upgrades/Focus/Tactic/TacticFocusAbility": true,
3317 "/Lotus/Upgrades/Focus/Ward/WardFocusAbility": true,
3318 "/Lotus/Upgrades/Focus/Defense/DefenseFocusAbility": true,
3319 "/Lotus/Upgrades/Focus/Power/PowerFocusAbility": true
3320 };
3321 if (data.FocusUpgrades) {
3322 for (const focusUpgrade of data.FocusUpgrades) {
3323 if (focusUpgrade.ItemType in missingFocusUpgrades) {
3324 delete missingFocusUpgrades[focusUpgrade.ItemType];
3308 3325 }
3309 3326 }
3310 for (const upgradeType of Object.keys(missingFocusUpgrades)) {
3311 await unlockFocusSchool(upgradeType);
3312 }
3313 if (Object.keys(missingFocusUpgrades).length == 0) {
3314 toast(loc("code_focusAllUnlocked"));
3315 } else {
3316 toast(loc("code_focusUnlocked").split("|COUNT|").join(Object.keys(missingFocusUpgrades).length));
3317 if (ws_is_open) {
3318 window.ws.send(JSON.stringify({ sync_inventory: true }));
3319 }
3327 }
3328 for (const upgradeType of Object.keys(missingFocusUpgrades)) {
3329 await unlockFocusSchool(upgradeType);
3330 }
3331 if (Object.keys(missingFocusUpgrades).length == 0) {
3332 toast(loc("code_focusAllUnlocked"));
3333 } else {
3334 toast(loc("code_focusUnlocked").split("|COUNT|").join(Object.keys(missingFocusUpgrades).length));
3335 if (ws_is_open) {
3336 window.ws.send(JSON.stringify({ sync_inventory: true }));
3320 3337 }
3321 3338 }
3322 );
3339 });
3323 3340 });
3324 3341 }
3325 3342
@@ -3445,8 +3462,7 @@ function doAddAllMods() {
3445 3462 modsAll.delete("/Lotus/Upgrades/Mods/Fusers/LegendaryModFuser");
3446 3463
3447 3464 revalidateAuthz().then(() => {
3448 const req = $.get("/api/inventory.php?" + window.authz + "&xpBasedLevelCapDisabled=1&ignoreBuildLabel=1");
3449 req.done(data => {
3465 getInventoryData().then(data => {
3450 3466 for (const modOwned of data.RawUpgrades) {
3451 3467 if ((modOwned.ItemCount ?? 1) > 0) {
3452 3468 modsAll.delete(modOwned.ItemType);
@@ -3477,8 +3493,7 @@ function doAddAllMods() {
3477 3493
3478 3494 function doRemoveUnrankedMods() {
3479 3495 revalidateAuthz().then(() => {
3480 const req = $.get("/api/inventory.php?" + window.authz + "&xpBasedLevelCapDisabled=1&ignoreBuildLabel=1");
3481 req.done(inventory => {
3496 getInventoryData().then(data => {
3482 3497 window.itemListPromise.then(itemMap => {
3483 3498 $.post({
3484 3499 url: "/api/sell.php?" + window.authz,
@@ -3559,7 +3574,7 @@ single.getRoute("#guild-route").on("beforeload", function () {
3559 3574 });
3560 3575 $("#guild-route > .row").addClass("d-none");
3561 3576 if (window.didInitialInventoryUpdate) {
3562 updateInventory();
3577 translateInventoryDataToDom();
3563 3578 }
3564 3579 });
3565 3580