优化 modelCurve 接口的调用时机,加上缓存,减少调用频率
This commit is contained in:
@@ -68,6 +68,8 @@ import { bandToPeqFilter, buildPeqCatalogSyncKey, cloneBands, getUniquePresetNam
|
|||||||
import type { BandParamKind, PeqCatalogItem, PeqEqUi, PeqPresetLocalCache } from "./eq/types";
|
import type { BandParamKind, PeqCatalogItem, PeqEqUi, PeqPresetLocalCache } from "./eq/types";
|
||||||
|
|
||||||
/* ── Main Component ── */
|
/* ── Main Component ── */
|
||||||
|
const rawCurveCache = new Map<string, number[] | null>();
|
||||||
|
|
||||||
export default function EQPage() {
|
export default function EQPage() {
|
||||||
const [, setLocation] = useLocation();
|
const [, setLocation] = useLocation();
|
||||||
const {
|
const {
|
||||||
@@ -158,6 +160,7 @@ export default function EQPage() {
|
|||||||
const [isConfirmingTarget, setIsConfirmingTarget] = useState(false);
|
const [isConfirmingTarget, setIsConfirmingTarget] = useState(false);
|
||||||
const [currentRawCurve, setCurrentRawCurve] = useState<number[] | null>(null);
|
const [currentRawCurve, setCurrentRawCurve] = useState<number[] | null>(null);
|
||||||
const [rawCurveLoading, setRawCurveLoading] = useState(false);
|
const [rawCurveLoading, setRawCurveLoading] = useState(false);
|
||||||
|
const rawCurveCacheRef = useRef(rawCurveCache);
|
||||||
const allowPeqRemoteSyncRef = useRef(false);
|
const allowPeqRemoteSyncRef = useRef(false);
|
||||||
const lastPeqCatalogSyncKeyRef = useRef("");
|
const lastPeqCatalogSyncKeyRef = useRef("");
|
||||||
const syncingHeadphoneRef = useRef(false);
|
const syncingHeadphoneRef = useRef(false);
|
||||||
@@ -828,6 +831,17 @@ export default function EQPage() {
|
|||||||
const model = peq?.model?.trim() ?? "";
|
const model = peq?.model?.trim() ?? "";
|
||||||
if (!brand || !model) return null;
|
if (!brand || !model) return null;
|
||||||
|
|
||||||
|
const cacheKey = `${brand}|${model}`;
|
||||||
|
if (rawCurveCacheRef.current.has(cacheKey)) {
|
||||||
|
const cached = rawCurveCacheRef.current.get(cacheKey);
|
||||||
|
if (cached) {
|
||||||
|
console.log("[modelCurve] cache hit", { brand, model, rawLength: cached.length });
|
||||||
|
} else {
|
||||||
|
console.log("[modelCurve] cache hit (no raw)", { brand, model });
|
||||||
|
}
|
||||||
|
return cached ?? null;
|
||||||
|
}
|
||||||
|
|
||||||
const modelCurve = await getModelCurve(brand, model);
|
const modelCurve = await getModelCurve(brand, model);
|
||||||
if (modelCurve && typeof modelCurve === "object") {
|
if (modelCurve && typeof modelCurve === "object") {
|
||||||
const payload = modelCurve as {
|
const payload = modelCurve as {
|
||||||
@@ -853,6 +867,7 @@ export default function EQPage() {
|
|||||||
})
|
})
|
||||||
: null;
|
: null;
|
||||||
const cleanedRaw = raw && raw.every((v) => Number.isFinite(v)) ? (raw as number[]) : null;
|
const cleanedRaw = raw && raw.every((v) => Number.isFinite(v)) ? (raw as number[]) : null;
|
||||||
|
rawCurveCacheRef.current.set(cacheKey, cleanedRaw);
|
||||||
console.log("[modelCurve] raw check", {
|
console.log("[modelCurve] raw check", {
|
||||||
brand,
|
brand,
|
||||||
model,
|
model,
|
||||||
|
|||||||
Reference in New Issue
Block a user