diff --git a/src/lib/components/WatchListCard.svelte b/src/lib/components/WatchListCard.svelte
index 5d65e74e..9a32e298 100644
--- a/src/lib/components/WatchListCard.svelte
+++ b/src/lib/components/WatchListCard.svelte
@@ -1,105 +1,12 @@
@@ -320,10 +277,10 @@ function handleWatchlistModal() {
My Watchlist
-
@@ -386,6 +381,7 @@ function handleWatchlistModal() {
@@ -464,112 +460,9 @@ function handleWatchlistModal() {
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/src/routes/watchlist/stocks/workers/downloadWorker.ts b/src/routes/watchlist/stocks/workers/downloadWorker.ts
new file mode 100644
index 00000000..c4885396
--- /dev/null
+++ b/src/routes/watchlist/stocks/workers/downloadWorker.ts
@@ -0,0 +1,57 @@
+// Cache to store previous requests
+let cache = new Map();
+
+const getStockScreenerData = async (rules) => {
+ console.log("Checking cache and fetching new data if needed");
+
+ // Extract the rule names
+ let getRuleOfList = rules?.map((rule) => rule.name) || [];
+
+ // Convert the rule set into a string key for the cache
+ const ruleKey = JSON.stringify(getRuleOfList);
+
+ // Check if data for this rule set is already in the cache
+ if (cache.has(ruleKey)) {
+ console.log("Returning cached data");
+ return cache.get(ruleKey);
+ }
+
+ // Fetch new data if it's not in the cache
+ const postData = { ruleOfList: getRuleOfList };
+ const response = await fetch("/api/stock-screener-data", {
+ method: "POST",
+ headers: {
+ "Content-Type": "application/json",
+ },
+ body: JSON.stringify(postData),
+ });
+
+ const output = await response.json();
+
+ // Store the new data in the cache
+ cache.set(ruleKey, output);
+
+ return output;
+};
+
+onmessage = async (event) => {
+ const { ruleOfList } = event.data || {};
+
+ const output = await getStockScreenerData(ruleOfList);
+
+ const stockScreenerData = output?.filter((item) =>
+ Object?.values(item)?.every(
+ (value) =>
+ value !== null &&
+ value !== undefined &&
+ (typeof value !== "object" ||
+ Object.values(value)?.every(
+ (subValue) => subValue !== null && subValue !== undefined
+ ))
+ )
+ );
+
+ postMessage({ message: "success", stockScreenerData });
+};
+
+export {};