This repository has been archived by the owner on Feb 22, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 50
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Cache waveform data in database (#510)
* Allow running specific tests * Document external binary and library dependencies * Cache audio waveform in database * Remove unnecessary abstractmethod * Add waveform directly to Audio model * Enable not following logs * Switch back to side-table for audio waveform data * Ensure refresh will not cause constraint errors * Apply linting changes * Use primary_key flag for audio id field on the add on
- Loading branch information
1 parent
0fa3575
commit 24a9bf1
Showing
9 changed files
with
138 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
# Generated by Django 3.2.12 on 2022-02-16 19:28 | ||
|
||
import django.contrib.postgres.fields | ||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('api', '0044_singular_category'), | ||
] | ||
|
||
operations = [ | ||
migrations.CreateModel( | ||
name='AudioAddOn', | ||
fields=[ | ||
('created_on', models.DateTimeField(auto_now_add=True)), | ||
('updated_on', models.DateTimeField(auto_now=True)), | ||
('audio_identifier', models.UUIDField(help_text='The identifier of the audio object.', primary_key=True, serialize=False)), | ||
('waveform_peaks', django.contrib.postgres.fields.ArrayField(base_field=models.FloatField(), help_text='The waveform peaks. A list of floats in the range of 0 -> 1 inclusively.', null=True, size=1500)), | ||
], | ||
options={ | ||
'abstract': False, | ||
}, | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import uuid | ||
from unittest import mock | ||
|
||
import pytest | ||
from catalog.api.models.audio import Audio, AudioAddOn | ||
|
||
|
||
@pytest.fixture | ||
@pytest.mark.django_db | ||
def audio_fixture(): | ||
audio = Audio( | ||
identifier=uuid.uuid4(), | ||
) | ||
|
||
audio.save() | ||
|
||
return audio | ||
|
||
|
||
@pytest.mark.django_db | ||
@mock.patch("catalog.api.models.audio.generate_peaks") | ||
def test_audio_waveform_caches(generate_peaks_mock, audio_fixture): | ||
mock_waveform = [0.4, 0.3, 0.1, 0, 1, 0.6] | ||
generate_peaks_mock.return_value = mock_waveform | ||
|
||
assert AudioAddOn.objects.count() == 0 | ||
assert audio_fixture.get_or_create_waveform() == mock_waveform | ||
assert AudioAddOn.objects.count() == 1 | ||
# Ensure the waveform was saved | ||
assert ( | ||
AudioAddOn.objects.get(audio_identifier=audio_fixture.identifier).waveform_peaks | ||
== mock_waveform | ||
) | ||
assert audio_fixture.get_or_create_waveform() == mock_waveform | ||
# Should only be called once if Audio.get_or_create_waveform is using the DB value on subsequent calls | ||
generate_peaks_mock.assert_called_once() | ||
|
||
# Ensure there are no foreign constraints on the AudioAddOn that would cause failures during refresh | ||
audio_fixture.delete() | ||
|
||
assert AudioAddOn.objects.count() == 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters