Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
f00f
Geike
Commits
52a8a6be
Verified
Commit
52a8a6be
authored
Mar 06, 2021
by
Luc Everse
Browse files
Remove stale cache entries
parent
384c3206
Pipeline
#1740
failed with stage
in 3 minutes and 37 seconds
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
geike2.js
View file @
52a8a6be
import
fs
from
'
fs
'
;
import
fsPromises
from
'
fs/promises
'
;
import
Discord
from
'
discord.js
'
;
import
ssdeep
from
'
ssdeep.js
'
;
import
{
parseISO
}
from
'
date-fns
'
;
...
...
@@ -81,6 +82,8 @@ client.on('ready', () => {
const
messageHandler
=
new
MessageHandler
(
config
,
logger
,
messageSender
,
guildRepo
,
commands
,
[]);
client
.
on
(
'
message
'
,
msg
=>
messageHandler
.
handle
(
msg
));
let
referencedCacheEntries
=
new
Set
();
(
async
()
=>
{
for
(
let
guild
of
Object
.
values
(
config
.
guilds
))
{
for
(
let
song
of
guild
.
songs
)
{
...
...
@@ -95,8 +98,10 @@ client.on('ready', () => {
console
.
log
(
`Hashed title
${
song
.
title
}
to
${
song
.
titleHash
}
`
);
}
const
cfp
=
songPlayer
.
getCacheFilePath
(
song
);
referencedCacheEntries
.
add
(
cfp
);
if
(
!
song
.
timestamp
)
{
const
cfp
=
songPlayer
.
getCacheFilePath
(
song
);
fs
.
stat
(
cfp
,
(
err
,
stats
)
=>
{
if
(
err
)
return
;
song
.
timestamp
=
new
Date
(
stats
.
mtimeMs
);
...
...
@@ -106,6 +111,18 @@ client.on('ready', () => {
}
}
}
const
cachePath
=
'
/var/lib/geike/cache
'
;
const
cacheFilenames
=
await
fsPromises
.
readdir
(
cachePath
);
await
Promise
.
all
(
cacheFilenames
.
map
(
f
=>
`
${
cachePath
}
/
${
f
}
`
)
.
filter
(
f
=>
!
referencedCacheEntries
.
has
(
f
))
.
map
(
f
=>
{
console
.
log
(
`Removing stale cache entry
${
f
}
`
)
return
fsPromises
.
rm
(
f
);
})
);
})().
catch
(
e
=>
logger
.
err
(
e
));
logger
.
log
(
`Logged in as
${
client
.
user
.
tag
}
!`
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment