feat(waveform): precompute and store peaks in DB for instant rendering
Store waveform peaks inline in audio_versions (JSONB columns) so WaveSurfer
can render the waveform immediately on page load without waiting for audio
decode. Adds a 100-point mini-waveform for version selector thumbnails.
Backend:
- Migration 0006: adds waveform_peaks and waveform_peaks_mini JSONB columns
- Worker generates both resolutions (500-pt full, 100-pt mini) during transcode
and stores them directly in DB — replaces file-based waveform_url approach
- AudioVersionRead schema exposes both fields inline (no extra HTTP round-trip)
- GET /versions/{id}/waveform reads from DB; adds ?resolution=mini support
Frontend:
- audioService.initialize() accepts peaks and calls ws.load(url, Float32Array)
so waveform renders instantly without audio decode
- useWaveform hook threads peaks option through to audioService
- PlayerPanel passes waveform_peaks from the active version to the hook
- New MiniWaveform SVG component (no WaveSurfer) renders mini peaks in the
version selector buttons
Fix: docker-compose.dev.yml now runs alembic upgrade head before starting
the API server, so a fresh volume gets the full schema automatically.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
35
api/alembic/versions/0006_waveform_peaks_in_db.py
Normal file
35
api/alembic/versions/0006_waveform_peaks_in_db.py
Normal file
@@ -0,0 +1,35 @@
|
||||
"""Store waveform peaks inline in audio_versions table.
|
||||
|
||||
Replaces file-based waveform_url approach with two JSONB columns:
|
||||
- waveform_peaks: 500-point peaks for the player (passed directly to WaveSurfer)
|
||||
- waveform_peaks_mini: 100-point peaks for library/overview mini-waveform SVG
|
||||
|
||||
Revision ID: 0006_waveform_peaks_in_db
|
||||
Revises: 0005_comment_tag
|
||||
Create Date: 2026-04-10
|
||||
"""
|
||||
|
||||
from alembic import op
|
||||
import sqlalchemy as sa
|
||||
from sqlalchemy.dialects.postgresql import JSONB
|
||||
|
||||
revision = "0006_waveform_peaks_in_db"
|
||||
down_revision = "0005_comment_tag"
|
||||
branch_labels = None
|
||||
depends_on = None
|
||||
|
||||
|
||||
def upgrade() -> None:
|
||||
op.add_column(
|
||||
"audio_versions",
|
||||
sa.Column("waveform_peaks", JSONB, nullable=True),
|
||||
)
|
||||
op.add_column(
|
||||
"audio_versions",
|
||||
sa.Column("waveform_peaks_mini", JSONB, nullable=True),
|
||||
)
|
||||
|
||||
|
||||
def downgrade() -> None:
|
||||
op.drop_column("audio_versions", "waveform_peaks_mini")
|
||||
op.drop_column("audio_versions", "waveform_peaks")
|
||||
Reference in New Issue
Block a user