Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
funkwhale
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository 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
Zwordi
funkwhale
Commits
428de178
Verified
Commit
428de178
authored
6 years ago
by
Eliot Berriot
Browse files
Options
Downloads
Patches
Plain Diff
Ensure cache_cleaning only targets remote files
parent
6572db3a
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
api/funkwhale_api/federation/tasks.py
+6
-3
6 additions, 3 deletions
api/funkwhale_api/federation/tasks.py
api/tests/federation/test_tasks.py
+7
-0
7 additions, 0 deletions
api/tests/federation/test_tasks.py
with
13 additions
and
3 deletions
api/funkwhale_api/federation/tasks.py
+
6
−
3
View file @
428de178
...
...
@@ -29,7 +29,8 @@ def clean_music_cache():
candidates
=
(
music_models
.
Upload
.
objects
.
filter
(
Q
(
audio_file__isnull
=
False
)
&
(
Q
(
accessed_date__lt
=
limit
)
|
Q
(
accessed_date
=
None
))
&
(
Q
(
accessed_date__lt
=
limit
)
|
Q
(
accessed_date
=
None
)),
# library__actor__user=None,
)
.
local
(
False
)
.
exclude
(
audio_file
=
""
)
...
...
@@ -55,8 +56,10 @@ def get_files(storage, *parts):
"""
if
not
parts
:
raise
ValueError
(
"
Missing path
"
)
dirs
,
files
=
storage
.
listdir
(
os
.
path
.
join
(
*
parts
))
try
:
dirs
,
files
=
storage
.
listdir
(
os
.
path
.
join
(
*
parts
))
except
FileNotFoundError
:
return
[]
for
dir
in
dirs
:
files
+=
get_files
(
storage
,
*
(
list
(
parts
)
+
[
dir
]))
return
[
os
.
path
.
join
(
parts
[
-
1
],
path
)
for
path
in
files
]
...
...
This diff is collapsed.
Click to expand it.
api/tests/federation/test_tasks.py
+
7
−
0
View file @
428de178
...
...
@@ -19,22 +19,29 @@ def test_clean_federation_music_cache_if_no_listen(preferences, factories):
accessed_date
=
timezone
.
now
()
-
datetime
.
timedelta
(
minutes
=
61
),
)
upload3
=
factories
[
"
music.Upload
"
](
library
=
remote_library
,
accessed_date
=
None
)
# local upload, should not be cleaned
upload4
=
factories
[
"
music.Upload
"
](
library__actor__local
=
True
,
accessed_date
=
None
)
path1
=
upload1
.
audio_file
.
path
path2
=
upload2
.
audio_file
.
path
path3
=
upload3
.
audio_file
.
path
path4
=
upload4
.
audio_file
.
path
tasks
.
clean_music_cache
()
upload1
.
refresh_from_db
()
upload2
.
refresh_from_db
()
upload3
.
refresh_from_db
()
upload4
.
refresh_from_db
()
assert
bool
(
upload1
.
audio_file
)
is
True
assert
bool
(
upload2
.
audio_file
)
is
False
assert
bool
(
upload3
.
audio_file
)
is
False
assert
bool
(
upload4
.
audio_file
)
is
True
assert
os
.
path
.
exists
(
path1
)
is
True
assert
os
.
path
.
exists
(
path2
)
is
False
assert
os
.
path
.
exists
(
path3
)
is
False
assert
os
.
path
.
exists
(
path4
)
is
True
def
test_clean_federation_music_cache_orphaned
(
settings
,
preferences
,
factories
):
...
...
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