Skip to content

Commit

Permalink
feat: speed up sources reloading process
Browse files Browse the repository at this point in the history
  • Loading branch information
CNSeniorious000 committed Aug 23, 2024
1 parent c3a8371 commit 669e6fe
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
8 changes: 7 additions & 1 deletion reasonify-headless/load.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import sys
from functools import cache
from os import chdir
from pathlib import Path
Expand All @@ -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:
Expand Down
6 changes: 1 addition & 5 deletions src/lib/components/Chat.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,12 @@
import type { Context } from "../types";
import type { PythonError } from "pyodide/ffi";
import { type Chain, getPy, initChain } from "../py";
import { type Chain, initChain } from "../py";
import Highlight from "./Highlight.svelte";
import Markdown from "./Markdown.svelte";
import { dev } from "$app/environment";
import { mount } from "$lib/py/fs";
import { pyodideReady, reasonifyReady, startIconAnimation, stopIconAnimation } from "$lib/stores";
import { globalCache } from "$lib/utils/cache";
import { toast } from "svelte-sonner";
export let chain: Chain;
Expand All @@ -23,9 +22,6 @@
async function refresh() {
refreshing = true;
try {
getPy.invalidateCache();
globalCache.clear();
$pyodideReady = false;
$reasonifyReady = false;
chain = await initChain();
} finally {
Expand Down

0 comments on commit 669e6fe

Please sign in to comment.