Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
U
ui-middleware
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Code review analytics
Issue analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Open Source Software
OX App Suite
Core
ui-middleware
Commits
15b00515
Commit
15b00515
authored
3 years ago
by
richard.petersen
Browse files
Options
Downloads
Patches
Plain Diff
Fix: /ready might trigger warmup multiple times
parent
32b50eb5
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
spec/startup_test.js
+57
-0
57 additions, 0 deletions
spec/startup_test.js
src/files.js
+6
-0
6 additions, 0 deletions
src/files.js
with
63 additions
and
0 deletions
spec/startup_test.js
0 → 100644
+
57
−
0
View file @
15b00515
import
{
generateSimpleViteManifest
,
mockApp
,
mockConfig
,
mockFetch
}
from
'
./util.js
'
import
{
expect
}
from
'
chai
'
import
*
as
td
from
'
testdouble
'
import
{
Response
}
from
'
node-fetch
'
describe
(
'
Service startup
'
,
function
()
{
before
(
async
function
()
{
mockConfig
({
urls
:
[
'
http://ui-server/
'
]
})
})
after
(
function
()
{
td
.
reset
()
})
it
(
'
only fetches all files once
'
,
async
function
()
{
const
counters
=
{
'
/example.js
'
:
0
,
'
/test.txt
'
:
0
,
'
/index.html.js
'
:
0
,
'
/index.html
'
:
0
}
mockFetch
({
'
http://ui-server
'
:
{
'
/manifest.json
'
:
generateSimpleViteManifest
({
'
example.js
'
:
{
imports
:
[
'
test.txt
'
]
},
'
test.txt
'
:
{
},
'
index.html
'
:
{
file
:
'
index.html.js
'
,
isEntry
:
true
,
imports
:
[
'
example.js
'
]
}
}),
'
/example.js
'
:
()
=>
{
counters
[
'
/example.js
'
]
++
return
new
Response
(
'
this is example
'
,
{
headers
:
{
'
content-type
'
:
'
application/javascript
'
}
})
},
'
/test.txt
'
:
()
=>
{
counters
[
'
/test.txt
'
]
++
return
new
Response
(
'
this is test
'
,
{
headers
:
{
'
content-type
'
:
'
text/plain
'
}
})
},
'
/index.html.js
'
:
()
=>
{
counters
[
'
/index.html.js
'
]
++
return
new
Response
(
'
this is index.html.js
'
,
{
headers
:
{
'
content-type
'
:
'
application/javascript
'
}
})
},
'
/index.html
'
:
()
=>
{
counters
[
'
/index.html
'
]
++
return
new
Response
(
'
<html><head></head><body>it
\'
s me</body></html>
'
,
{
headers
:
{
'
content-type
'
:
'
text/html
'
}
})
}
}
})
await
mockApp
()
Object
.
entries
(
counters
).
forEach
(([
key
,
value
])
=>
{
expect
(
value
,
`
${
key
}
`
).
to
.
equal
(
1
)
})
})
})
This diff is collapsed.
Click to expand it.
src/files.js
+
6
−
0
View file @
15b00515
...
...
@@ -38,9 +38,14 @@ class FileCache {
this
.
_hash
=
''
this
.
_dependencies
=
{}
this
.
_oxManifests
=
{}
this
.
_isCaching
=
false
}
async
warmUp
(
manifests
,
deps
)
{
if
(
this
.
_hash
===
manifests
.
__hash__
)
return
logger
.
debug
(
`Tried to warm up the filecache with the same version:
${
manifests
.
__hash__
}
`
)
if
(
this
.
_isCaching
)
return
logger
.
debug
(
'
Cache.warmup is already running
'
)
this
.
_isCaching
=
true
logger
.
debug
(
'
beginning to warm up cache
'
)
const
cache
=
Object
.
fromEntries
(
await
(
async
function
()
{
const
files
=
Object
.
keys
(
deps
)
...
...
@@ -79,6 +84,7 @@ class FileCache {
this
.
_hash
=
manifests
.
__hash__
this
.
_dependencies
=
deps
this
.
_oxManifests
=
viteToOxManifest
(
manifests
)
this
.
_isCaching
=
false
logger
.
debug
(
'
cache warmed up
'
)
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment