perf: tighten director tag and segment helpers

This commit is contained in:
OpenClaw Agent
2026-07-09 20:03:37 +00:00
parent 58469ccb4b
commit 39af2b0150
2 changed files with 52 additions and 43 deletions

View File

@@ -53,7 +53,15 @@ function stripAudioSegmentTransient(s) {
}
function dedupeById(items = []) {
return items.filter((seg, index, self) => index === self.findIndex((s) => s.id === seg.id));
const seen = new Set();
const deduped = [];
for (const seg of items || []) {
const id = seg?.id;
if (!id || seen.has(id)) continue;
seen.add(id);
deduped.push(seg);
}
return deduped;
}
function findActiveSegmentAtFrame(segments = [], targetFrame, type) {
@@ -61,6 +69,10 @@ function findActiveSegmentAtFrame(segments = [], targetFrame, type) {
(seg) => seg?.type === type && targetFrame >= seg.start && targetFrame < seg.start + seg.length
);
}
function segmentMatchesAudioSource(seg, audioFile, blobUrl) {
return !!seg && (seg.audioFile === audioFile || seg._blobUrl === blobUrl);
}
function hideWidget(w) {
if (!w) return;
@@ -2004,6 +2016,14 @@ class TimelineEditor {
return found;
}
_forEachMatchingAudioSegment(audioFile, blobUrl, visitor) {
for (const seg of this.timeline.audioSegments || []) {
if (segmentMatchesAudioSource(seg, audioFile, blobUrl)) {
visitor(seg);
}
}
}
_getSegmentsByFileKey(fileKey) {
const matches = [];
this._forEachMatchingSegment(fileKey, (seg) => {
@@ -2231,11 +2251,10 @@ class TimelineEditor {
const audioBuffer = await this._loadAudioBuffer(seg);
const matchingSegs = this.timeline.audioSegments.filter(s => s.audioFile === seg.audioFile || s._blobUrl === seg._blobUrl);
for (const s of matchingSegs) {
s._audioBuffer = audioBuffer;
s._decoding = false;
}
this._forEachMatchingAudioSegment(seg.audioFile, seg._blobUrl, (s) => {
s._audioBuffer = audioBuffer;
s._decoding = false;
});
} catch (err) {
console.warn("Failed to preload audio segment:", err);
seg._decoding = false;