See #228: more performante federation import launch via API

merge-requests/237/head
Eliot Berriot 2018-05-24 18:53:12 +02:00
rodzic 4f8db661fa
commit eded32c2e8
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: DD6965E2476E5C27
4 zmienionych plików z 25 dodań i 7 usunięć

Wyświetl plik

@ -834,17 +834,17 @@ class LibraryTrackActionSerializer(common_serializers.ActionSerializer):
source='federation', source='federation',
submitted_by=self.context['submitted_by'] submitted_by=self.context['submitted_by']
) )
jobs = []
for lt in objects: for lt in objects:
job = music_models.ImportJob.objects.create( job = music_models.ImportJob(
batch=batch, batch=batch,
library_track=lt, library_track=lt,
mbid=lt.mbid, mbid=lt.mbid,
source=lt.url, source=lt.url,
) )
funkwhale_utils.on_commit( jobs.append(job)
music_tasks.import_job_run.delay,
import_job_id=job.pk, music_models.ImportJob.objects.bulk_create(jobs)
use_acoustid=False, music_tasks.import_batch_run.delay(import_batch_id=batch.pk)
)
return {'batch': {'id': batch.pk}} return {'batch': {'id': batch.pk}}

Wyświetl plik

@ -173,6 +173,13 @@ def import_job_run(self, import_job, replace=False, use_acoustid=False):
raise raise
@celery.app.task(name='ImportBatch.run')
@celery.require_instance(models.ImportBatch, 'import_batch')
def import_batch_run(import_batch):
for job_id in import_batch.jobs.order_by('id').values_list('id', flat=True):
import_job_run.delay(import_job_id=job_id)
@celery.app.task(name='Lyrics.fetch_content') @celery.app.task(name='Lyrics.fetch_content')
@celery.require_instance(models.Lyrics, 'lyrics') @celery.require_instance(models.Lyrics, 'lyrics')
def fetch_content(lyrics): def fetch_content(lyrics):

Wyświetl plik

@ -426,7 +426,8 @@ def test_library_track_action_import(
lt2 = factories['federation.LibraryTrack'](library=lt1.library) lt2 = factories['federation.LibraryTrack'](library=lt1.library)
lt3 = factories['federation.LibraryTrack']() lt3 = factories['federation.LibraryTrack']()
lt4 = factories['federation.LibraryTrack'](library=lt3.library) lt4 = factories['federation.LibraryTrack'](library=lt3.library)
mocker.patch('funkwhale_api.music.tasks.import_job_run') mocked_run = mocker.patch(
'funkwhale_api.music.tasks.import_batch_run.delay')
payload = { payload = {
'objects': 'all', 'objects': 'all',
@ -452,3 +453,4 @@ def test_library_track_action_import(
assert batch.jobs.count() == 2 assert batch.jobs.count() == 2
for i, job in enumerate(batch.jobs.all()): for i, job in enumerate(batch.jobs.all()):
assert job.library_track == imported_lts[i] assert job.library_track == imported_lts[i]
mocked_run.assert_called_once_with(import_batch_id=batch.pk)

Wyświetl plik

@ -47,6 +47,15 @@ def test_set_acoustid_on_track_file_required_high_score(factories, mocker):
assert track_file.acoustid_track_id is None assert track_file.acoustid_track_id is None
def test_import_batch_run(factories, mocker):
job = factories['music.ImportJob']()
mocked_job_run = mocker.patch(
'funkwhale_api.music.tasks.import_job_run.delay')
tasks.import_batch_run(import_batch_id=job.batch.pk)
mocked_job_run.assert_called_once_with(import_job_id=job.pk)
def test_import_job_can_run_with_file_and_acoustid( def test_import_job_can_run_with_file_and_acoustid(
artists, albums, tracks, preferences, factories, mocker): artists, albums, tracks, preferences, factories, mocker):
preferences['providers_acoustid__api_key'] = 'test' preferences['providers_acoustid__api_key'] = 'test'