From 0e5d991c8d33cedea636640c519c8f04b956b37c Mon Sep 17 00:00:00 2001
From: AAGaming <aa@mail.catvibers.me>
Date: Sat, 31 Dec 2022 23:27:04 -0500
Subject: add patch caching

---
 frontend/src/menu-hook.tsx | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)

(limited to 'frontend/src/menu-hook.tsx')

diff --git a/frontend/src/menu-hook.tsx b/frontend/src/menu-hook.tsx
index ad09bc38..810b6dfa 100644
--- a/frontend/src/menu-hook.tsx
+++ b/frontend/src/menu-hook.tsx
@@ -69,6 +69,7 @@ class MenuHook extends Logger {
       this.menuRenderer = menuRenderer;
       this.originalRenderer = menuRenderer.type;
       let toReplace = new Map<string, ReactNode>();
+      let alreadyPatched = new Map<string, { total: number; node: ReactNode }>();
 
       let patchedInnerMenu: any;
       let overlayComponentManager: any;
@@ -132,6 +133,17 @@ class MenuHook extends Logger {
                 toReplace.delete(item?.props.route as string);
               }
               if (item?.props?.route && (itemPatches.has(item.props.route as string) || itemPatches.has('*'))) {
+                if (
+                  item?.props?.route && 
+                  alreadyPatched.has(item.props.route) &&
+                  alreadyPatched.get(item.props.route)?.total ==
+                    (itemPatches.get(item.props.route)?.size || 0) + (itemPatches.get('*')?.size || 0)
+                ) {
+                  const patched = alreadyPatched.get(item.props.route);
+                  this.debug('found already patched', patched);
+                  itemList[index] = patched?.node;
+                  return;
+                }
                 toReplace.set(item?.props?.route as string, itemList[index]);
                 itemPatches.get(item.props.route as string)?.forEach((patch) => {
                   const oType = itemList[index].type;
@@ -147,6 +159,10 @@ class MenuHook extends Logger {
                     type: (props: any) => createElement(oType, props),
                   });
                 });
+                alreadyPatched.set(item.props.route, {
+                  total: (itemPatches.get(item.props.route)?.size || 0) + (itemPatches.get('*')?.size || 0),
+                  node: itemList[index],
+                });
               }
             });
 
-- 
cgit v1.2.3

