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
3e0419d9
Commit
3e0419d9
authored
2 years ago
by
richard.petersen
Browse files
Options
Downloads
Patches
Plain Diff
add: ui-middleware will slowly warm it's caches after version updates
parent
28a9f92d
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
src/files.js
+18
-0
18 additions, 0 deletions
src/files.js
src/index.js
+8
-0
8 additions, 0 deletions
src/index.js
src/version.js
+3
-0
3 additions, 0 deletions
src/version.js
with
29 additions
and
0 deletions
src/files.js
+
18
−
0
View file @
3e0419d9
...
...
@@ -84,3 +84,21 @@ export function getFile ({ version, path }) {
return
fetchFileWithHeaders
({
version
,
path
})
})
}
export
async
function
warmCache
({
version
})
{
const
start
=
+
new
Date
()
logger
.
info
(
'
[File] start warming up the cache
'
)
const
viteManifests
=
await
getViteManifests
({
version
})
for
(
const
key
of
Object
.
keys
(
viteManifests
))
{
const
path
=
`/
${
viteManifests
[
key
].
file
}
`
if
(
!
path
)
continue
try
{
await
getFile
({
version
,
path
})
}
catch
(
err
)
{
logger
.
info
(
`[File] could not prefetch file
${
path
}
`
)
}
}
logger
.
info
(
`[File] finished warming up the cache in
${
Math
.
floor
((
+
new
Date
()
-
start
)
/
1000
)}
s`
)
}
This diff is collapsed.
Click to expand it.
src/index.js
+
8
−
0
View file @
3e0419d9
...
...
@@ -8,6 +8,7 @@ import { configMap } from './configMap.js'
import
*
as
redis
from
'
./redis.js
'
import
lightshipCjs
from
'
lightship
'
import
{
createMetricsServer
}
from
'
./metrics.js
'
import
{
warmCache
}
from
'
./files.js
'
config
()
...
...
@@ -26,6 +27,13 @@ app.addHook('onReady', () => {
lightship
.
signalReady
()
})
app
.
addHook
(
'
onReady
'
,
()
=>
{
// don't block the onReady hook
getLatestVersion
()
.
then
(
version
=>
warmCache
({
version
}))
.
catch
(
err
=>
logger
.
error
(
err
))
})
// Binds and listens for connections on the specified host and port
app
.
listen
({
host
:
'
::
'
,
port
:
Number
(
process
.
env
.
PORT
)
})
...
...
This diff is collapsed.
Click to expand it.
src/version.js
+
3
−
0
View file @
3e0419d9
...
...
@@ -5,6 +5,7 @@ import * as cache from './cache.js'
import
*
as
redis
from
'
./redis.js
'
import
{
Gauge
}
from
'
prom-client
'
import
{
getViteManifests
}
from
'
./manifests.js
'
import
{
warmCache
}
from
'
./files.js
'
let
latestVersion
...
...
@@ -80,6 +81,7 @@ export function registerLatestVersionListener (client) {
await
configMap
.
load
()
versionUpdateGauge
.
setToCurrentTime
({
version
})
cache
.
clear
()
warmCache
({
version
}).
catch
(
err
=>
logger
.
error
(
err
))
latestVersion
=
version
})
}
...
...
@@ -121,6 +123,7 @@ export async function updateVersionProcessor () {
// if redis is disabled, this will only be trigger by a setInterval and not from a redis event
logger
.
info
(
'
[Version] Clear local cache due to version update.
'
)
cache
.
clear
()
warmCache
({
version
:
fetchedVersion
}).
catch
(
err
=>
logger
.
error
(
err
))
latestVersion
=
fetchedVersion
}
return
latestVersion
...
...
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