Skip to content

Cache waveform peaks and use direct URLs for faster replay loads#1223

Open
hilsonshrestha wants to merge 8 commits into
devfrom
1174-replay-videos-should-load-faster
Open

Cache waveform peaks and use direct URLs for faster replay loads#1223
hilsonshrestha wants to merge 8 commits into
devfrom
1174-replay-videos-should-load-faster

Conversation

@hilsonshrestha

@hilsonshrestha hilsonshrestha commented May 7, 2026

Copy link
Copy Markdown
Contributor

Does this PR close any open issues?

Closes #1174

Give a longer description of what this PR addresses and why it's needed

Audio and screen recording replays were slow because WaveSurfer had to fully decode audio on every load to render the waveform. This PR caches decoded waveform peaks to storage after the first load so subsequent visits skip decoding. It also replaces entire blob fetches of audio and video with direct URL calls so that the media player can buffer stream.

PR also shows a warning when participant used a browser different.

PR adds a Firebase Cloud Function that runs ffmpeg on uploaded screen recordings to re-encode them as webm using a stream copy (no re-encoding when the source is already webm-compatible).

Provide pictures/videos of the behavior before and after these changes (optional)

image

Are there any additional TODOs before this PR is ready to go?

x

Copilot AI review requested due to automatic review settings May 7, 2026 14:17
@github-actions

github-actions Bot commented May 7, 2026

Copy link
Copy Markdown

A preview of 1cb2444 is uploaded and can be seen here:

https://revisit.dev/study/PR1223

Changes may take a few minutes to propagate.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Improves replay performance by avoiding repeated full audio decode for waveform rendering and by switching replay media loading from full-blob fetches to direct URLs so the browser can stream/buffer.

Changes:

  • Added support for caching/loading WaveSurfer waveform peaks via the storage engine.
  • Updated replay components to use direct screen recording URLs instead of blob/object URLs.
  • Updated audio provenance visualization to load cached peaks when available and persist peaks after first load.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.

File Description
src/storage/engines/types.ts Adds WaveformPeaks type + storage helpers for saving/loading cached peaks; adds screen recording URL getter.
src/components/screenRecording/ScreenRecordingReplay.tsx Switches screen recording replay source to direct URL loading.
src/components/audioAnalysis/AudioProvenanceVis.tsx Adds waveform peak caching logic and switches to direct media URLs for faster load.
src/analysis/individualStudy/thinkAloud/ThinkAloudFooter.tsx Switches think-aloud footer screen recording load to direct URL.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/components/audioAnalysis/AudioProvenanceVis.tsx
Comment on lines +936 to +939
async getWaveformPeaks(taskName: string, participantId: string): Promise<WaveformPeaks | null> {
const result = await this._getFromStorage(`audio/${participantId}_${taskName}`, 'waveform.peaks.json');
if (!result || !('peaks' in result)) return null;
return result as WaveformPeaks;

@JackWilb JackWilb left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Two blocking issues need to be addressed before merge. CI also needs to be fixed: the committed ScreenRecordingReplay unit tests still mock the old storage method, causing the Vitest workflow to fail with one failed assertion and unhandled rejections.

Comment thread functions/src/index.ts
}

const fileName = path.basename(filePath);
const tmpInput = path.join(os.tmpdir(), fileName);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P1] Second-generation functions can process events concurrently, but these temp paths use only the object basename. Identically named participant/task recordings from different studies can overwrite each other and corrupt the converted upload. Please create a unique temp directory per event (for example with fs.mkdtemp) or include a full-path hash/event ID in both paths, then clean it up in finally.

throw new Error('Participant ID is required to load audio');
}
const url = await storageEngine.getScreenRecording(identifier, participantId);
const url = await storageEngine.getScreenRecordingUrl(identifier, participantId);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P1] This method was renamed to getScreenRecordingUrl, but the sibling spec still mocks getScreenRecording. The focused Vitest run fails and emits unhandled rejections because the new method is missing. Please update the null, success, and video-src test mocks to expose getScreenRecordingUrl; CI needs to pass before merge.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants