Skip to content

Commit 813fcf7

Browse files
committedDec 4, 2024
Deploying to wws from @ f0a4ee1 🚀
1 parent 441d0fe commit 813fcf7

32 files changed

+1960
-1840
lines changed
 

‎fusion/Fusion.ts

Lines changed: 37 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -48,34 +48,52 @@ const importOnlyRegex = /^importOnly/
4848

4949
const isUrl = (path: string) => urlRegex.test(path)
5050

51-
// URL content cache
52-
const urlCache: { [url: string]: { content: string; timestamp: number } } = {}
51+
// URL content cache with pending requests tracking
52+
const urlCache: { [url: string]: { content: string; timestamp: number; exists: boolean } } = {}
53+
const pendingRequests: { [url: string]: Promise<{ content: string; timestamp: number; exists: boolean }> } = {}
5354

5455
async function fetchWithCache(url: string) {
5556
const now = Date.now()
5657
const cached = urlCache[url]
5758

5859
if (cached) return cached
5960

60-
try {
61-
const response = await fetch(url)
62-
if (!response.ok) throw new Error(`HTTP error! status: ${response.status}`)
63-
const content = await response.text()
61+
// If there's already a pending request for this URL, return that promise
62+
if (pendingRequests[url]) {
63+
return pendingRequests[url]
64+
}
6465

65-
urlCache[url] = {
66-
content,
67-
timestamp: now,
68-
exists: true
69-
}
70-
} catch (error) {
71-
console.error(`Error fetching ${url}:`, error)
72-
urlCache[url] = {
73-
content: "",
74-
timestamp: now,
75-
exists: false
66+
// Create new request and store in pending
67+
const requestPromise = (async () => {
68+
try {
69+
const response = await fetch(url)
70+
if (!response.ok) throw new Error(`HTTP error! status: ${response.status}`)
71+
const content = await response.text()
72+
73+
const result = {
74+
content,
75+
timestamp: now,
76+
exists: true
77+
}
78+
79+
urlCache[url] = result
80+
return result
81+
} catch (error) {
82+
console.error(`Error fetching ${url}:`, error)
83+
const result = {
84+
content: "",
85+
timestamp: now,
86+
exists: false
87+
}
88+
urlCache[url] = result
89+
return result
90+
} finally {
91+
delete pendingRequests[url]
7692
}
77-
}
78-
return urlCache[url]
93+
})()
94+
95+
pendingRequests[url] = requestPromise
96+
return requestPromise
7997
}
8098

8199
class DiskWriter implements Storage {

‎node_modules/.package-lock.json

Lines changed: 7 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎node_modules/gopd/CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎node_modules/gopd/gOPD.d.ts

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎node_modules/gopd/gOPD.js

Lines changed: 4 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎node_modules/gopd/index.js

Lines changed: 1 addition & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎node_modules/gopd/package.json

Lines changed: 3 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎node_modules/has-symbols/CHANGELOG.md

Lines changed: 16 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎node_modules/has-symbols/index.d.ts

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎node_modules/has-symbols/index.js

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎node_modules/has-symbols/package.json

Lines changed: 19 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎node_modules/has-symbols/shams.d.ts

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎node_modules/has-symbols/shams.js

Lines changed: 5 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎node_modules/has-symbols/test/shams/core-js.js

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎node_modules/has-symbols/test/shams/get-own-property-symbols.js

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎node_modules/has-symbols/test/tests.js

Lines changed: 4 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎node_modules/has-symbols/tsconfig.json

Lines changed: 10 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)