From d8547dba26ebfc989bcea84b09a117ffd4ae739b Mon Sep 17 00:00:00 2001
From: Muspi Merol <wjj123345567@icloud.com>
Date: Fri, 23 Aug 2024 12:21:06 +0800
Subject: [PATCH] feat: speed up sources reloading process

---
 reasonify-headless/load.py     | 8 +++++++-
 src/lib/components/Chat.svelte | 3 ---
 2 files changed, 7 insertions(+), 4 deletions(-)

diff --git a/reasonify-headless/load.py b/reasonify-headless/load.py
index e834493..f2f71f9 100644
--- a/reasonify-headless/load.py
+++ b/reasonify-headless/load.py
@@ -1,3 +1,4 @@
+import sys
 from functools import cache
 from os import chdir
 from pathlib import Path
@@ -15,12 +16,17 @@ def with_toast[**Params, Return](message: str) -> Callable[[Callable[Params, Ret
 
 
 for path, source in sources.items():
-    file = Path(path)
+    file = Path("/home/pyodide", path)
     if not file.parent.is_dir():
         file.parent.mkdir(parents=True)
     file.write_text(source, "utf-8")
 
 
+if __debug__:
+    for module in tuple(sys.modules):  # for HMR
+        if module.startswith("reasonify"):
+            sys.modules.pop(module).__dict__.clear()
+
 if TYPE_CHECKING:
 
     class NativeFS:
diff --git a/src/lib/components/Chat.svelte b/src/lib/components/Chat.svelte
index 09d55e2..2cc62c4 100644
--- a/src/lib/components/Chat.svelte
+++ b/src/lib/components/Chat.svelte
@@ -23,9 +23,6 @@
   async function refresh() {
     refreshing = true;
     try {
-      getPy.invalidateCache();
-      globalCache.clear();
-      $pyodideReady = false;
       $reasonifyReady = false;
       chain = await initChain();
     } finally {