修复强制计算后,清除缓存,但是没有重新获取当前时刻的数据的问题
This commit is contained in:
@@ -426,6 +426,41 @@ const Timeline: React.FC<TimelineProps> = ({
|
||||
}
|
||||
}, [map, handlePause]);
|
||||
|
||||
const clearCacheAndRefetch = (date: Date, timeInMinutes: number) => {
|
||||
const dateStr = date.toISOString().split("T")[0];
|
||||
|
||||
const clearCache = (
|
||||
cacheRef: React.MutableRefObject<Map<string, any[]>>
|
||||
) => {
|
||||
const cacheKeys = Array.from(cacheRef.current.keys());
|
||||
cacheKeys.forEach((key) => {
|
||||
const keyParts = key.split("_");
|
||||
const cacheDate = keyParts[0].split("T")[0];
|
||||
const cacheTimeStr = keyParts[0].split("T")[1];
|
||||
|
||||
if (cacheDate === dateStr && cacheTimeStr) {
|
||||
const [hours, minutes] = cacheTimeStr.split(":");
|
||||
const cacheTimeInMinutes = parseInt(hours) * 60 + parseInt(minutes);
|
||||
|
||||
if (cacheTimeInMinutes >= timeInMinutes) {
|
||||
cacheRef.current.delete(key);
|
||||
}
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
clearCache(nodeCacheRef);
|
||||
clearCache(linkCacheRef);
|
||||
|
||||
// 重新获取当前时刻的新数据
|
||||
fetchFrameData(
|
||||
currentTimeToDate(selectedDate, currentTime),
|
||||
junctionText,
|
||||
pipeText,
|
||||
schemeName
|
||||
);
|
||||
};
|
||||
|
||||
const handleForceCalculate = async () => {
|
||||
if (!NETWORK_NAME) {
|
||||
open?.({
|
||||
@@ -467,43 +502,8 @@ const Timeline: React.FC<TimelineProps> = ({
|
||||
);
|
||||
|
||||
if (response.ok) {
|
||||
// 清空当天当前时刻及之后的缓存
|
||||
const currentDateStr = calculationDateStr;
|
||||
const currentTimeInMinutes = calculationTime;
|
||||
|
||||
// 清空node缓存
|
||||
const nodeCacheKeys = Array.from(nodeCacheRef.current.keys());
|
||||
nodeCacheKeys.forEach((key) => {
|
||||
const keyParts = key.split("_");
|
||||
const cacheDate = keyParts[0].split("T")[0];
|
||||
const cacheTimeStr = keyParts[0].split("T")[1];
|
||||
|
||||
if (cacheDate === currentDateStr && cacheTimeStr) {
|
||||
const [hours, minutes] = cacheTimeStr.split(":");
|
||||
const cacheTimeInMinutes = parseInt(hours) * 60 + parseInt(minutes);
|
||||
|
||||
if (cacheTimeInMinutes >= currentTimeInMinutes) {
|
||||
nodeCacheRef.current.delete(key);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
// 清空link缓存
|
||||
const linkCacheKeys = Array.from(linkCacheRef.current.keys());
|
||||
linkCacheKeys.forEach((key) => {
|
||||
const keyParts = key.split("_");
|
||||
const cacheDate = keyParts[0].split("T")[0];
|
||||
const cacheTimeStr = keyParts[0].split("T")[1];
|
||||
|
||||
if (cacheDate === currentDateStr && cacheTimeStr) {
|
||||
const [hours, minutes] = cacheTimeStr.split(":");
|
||||
const cacheTimeInMinutes = parseInt(hours) * 60 + parseInt(minutes);
|
||||
|
||||
if (cacheTimeInMinutes >= currentTimeInMinutes) {
|
||||
linkCacheRef.current.delete(key);
|
||||
}
|
||||
}
|
||||
});
|
||||
// 清空当天当前时刻及之后的缓存并重新获取数据
|
||||
clearCacheAndRefetch(calculationDate, calculationTime);
|
||||
|
||||
open?.({
|
||||
type: "success",
|
||||
|
||||
Reference in New Issue
Block a user