Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
funkwhale_OLD
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
jovuit
funkwhale_OLD
Commits
ced85189
Verified
Commit
ced85189
authored
6 years ago
by
Eliot Berriot
Browse files
Options
Downloads
Patches
Plain Diff
Fix #163: Avoid downloading audio files multiple times from remote libraries
parent
fc4f0068
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/music/views.py
+18
-9
18 additions, 9 deletions
api/funkwhale_api/music/views.py
changes/changelog.d/163.enhancement
+1
-0
1 addition, 0 deletions
changes/changelog.d/163.enhancement
with
19 additions
and
9 deletions
api/funkwhale_api/music/views.py
+
18
−
9
View file @
ced85189
...
...
@@ -23,13 +23,14 @@ from rest_framework import permissions
from
musicbrainzngs
import
ResponseError
from
funkwhale_api.common
import
utils
as
funkwhale_utils
from
funkwhale_api.federation
import
actors
from
funkwhale_api.requests.models
import
ImportRequest
from
funkwhale_api.musicbrainz
import
api
from
funkwhale_api.common.permissions
import
(
ConditionalAuthentication
,
HasModelPermission
)
from
taggit.models
import
Tag
from
funkwhale_api.federation
import
actors
from
funkwhale_api.federation.authentication
import
SignatureAuthentication
from
funkwhale_api.federation.models
import
LibraryTrack
from
funkwhale_api.musicbrainz
import
api
from
funkwhale_api.requests.models
import
ImportRequest
from
.
import
filters
from
.
import
forms
...
...
@@ -195,12 +196,13 @@ class TrackFileViewSet(viewsets.ReadOnlyModelViewSet):
@detail_route
(
methods
=
[
'
get
'
])
def
serve
(
self
,
request
,
*
args
,
**
kwargs
):
queryset
=
models
.
TrackFile
.
objects
.
select_related
(
'
library_track
'
,
'
track__album__artist
'
,
'
track__artist
'
,
)
try
:
f
=
models
.
TrackFile
.
objects
.
select_related
(
'
library_track
'
,
'
track__album__artist
'
,
'
track__artist
'
,
).
get
(
pk
=
kwargs
[
'
pk
'
])
f
=
queryset
.
get
(
pk
=
kwargs
[
'
pk
'
])
except
models
.
TrackFile
.
DoesNotExist
:
return
Response
(
status
=
404
)
...
...
@@ -213,7 +215,14 @@ class TrackFileViewSet(viewsets.ReadOnlyModelViewSet):
if
library_track
and
not
audio_file
:
if
not
library_track
.
audio_file
:
# we need to populate from cache
library_track
.
download_audio
()
with
transaction
.
atomic
():
# why the transaction/select_for_update?
# this is because browsers may send multiple requests
# in a short time range, for partial content,
# thus resulting in multiple downloads from the remote
qs
=
LibraryTrack
.
objects
.
select_for_update
()
library_track
=
qs
.
get
(
pk
=
library_track
.
pk
)
library_track
.
download_audio
()
audio_file
=
library_track
.
audio_file
mt
=
library_track
.
audio_mimetype
response
=
Response
()
...
...
This diff is collapsed.
Click to expand it.
changes/changelog.d/163.enhancement
0 → 100644
+
1
−
0
View file @
ced85189
Avoid downloading audio files multiple times from remote libraries (#163)
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