feat: add rank cache
This commit is contained in:
+23
-6
@@ -1,4 +1,5 @@
|
|||||||
const BACKEND_URL = "https://rank.intcplab.cn";
|
const BACKEND_URL = "https://rank.intcplab.cn";
|
||||||
|
const cache = {};
|
||||||
|
|
||||||
// 获取数据的函数
|
// 获取数据的函数
|
||||||
async function fetchScoresData(para, project, inject) {
|
async function fetchScoresData(para, project, inject) {
|
||||||
@@ -25,21 +26,37 @@ async function fetchScoresData(para, project, inject) {
|
|||||||
|
|
||||||
tableBody.appendChild(row);
|
tableBody.appendChild(row);
|
||||||
});
|
});
|
||||||
|
cache[`${project}_${para}`] = data;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error("获取数据时发生错误:", error);
|
console.error("获取数据时发生错误:", error);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 显示详情的函数
|
// 显示详情的函数
|
||||||
function showDetailsModal(para, project, index) {
|
async function showDetailsModal(para, project, index) {
|
||||||
const modal = document.getElementById("detailsModal");
|
const modal = document.getElementById("detailsModal");
|
||||||
const modalDetails = document.getElementById("modal-details");
|
const modalDetails = document.getElementById("modal-details");
|
||||||
fetch(`${BACKEND_URL}/get_scores/${project}?sort_by=${para}`)
|
|
||||||
.then((response) => response.json())
|
let data;
|
||||||
.then((data) => {
|
if (cache[`${project}_${para}`]) {
|
||||||
modalDetails.innerHTML = data[index].details + "<br><br>" + (data[index].hash ? `若<b>仓库设置</b>为公开,则可<a href="${data[index].hash}" target="_blank">点击查看</a>评测所对应提交<br><br>` : "");
|
data = cache[`${project}_${para}`];
|
||||||
|
} else {
|
||||||
|
try {
|
||||||
|
const response = await fetch(`${BACKEND_URL}/get_scores/${project}?sort_by=${para}`);
|
||||||
|
data = await response.json();
|
||||||
|
// 缓存数据
|
||||||
|
cache[`${project}_${para}`] = data;
|
||||||
|
} catch (error) {
|
||||||
|
console.error("Failed to fetch data:", error);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const details = data[index].details;
|
||||||
|
const hashLink = data[index].hash ? `若<b>仓库设置</b>为公开,则可<a href="${data[index].hash}" target="_blank">点击查看</a>评测所对应提交<br><br>` : "";
|
||||||
|
|
||||||
|
modalDetails.innerHTML = details + "<br><br>" + hashLink;
|
||||||
modal.style.display = "block";
|
modal.style.display = "block";
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// 关闭模态框
|
// 关闭模态框
|
||||||
|
|||||||
Reference in New Issue
Block a user