perf: streamline repository and deployment awareness
ForgeFlow quality gate / quality (push) Canceled after 0s
ForgeFlow quality gate / quality (push) Canceled after 0s
This commit is contained in:
+51
-3
@@ -178,6 +178,10 @@ const ui = {
|
||||
refreshError: null,
|
||||
refreshWarning: null,
|
||||
autoRefreshPending: false,
|
||||
repositoryRefreshPromise: null,
|
||||
repositoryRefreshRequest: null,
|
||||
deploymentTruthPromise: null,
|
||||
deploymentTruthRequest: null,
|
||||
paletteQuery: "",
|
||||
updateStatus: null,
|
||||
updateChecking: false,
|
||||
@@ -424,10 +428,32 @@ function scheduleAutoRefresh() {
|
||||
}
|
||||
|
||||
async function refreshRepositories(withLoader = true, silent = false) {
|
||||
ui.repositoryRefreshRequest = {
|
||||
withLoader: ui.repositoryRefreshRequest?.withLoader === true || withLoader,
|
||||
silent: ui.repositoryRefreshRequest ? ui.repositoryRefreshRequest.silent && silent : silent,
|
||||
};
|
||||
if (ui.repositoryRefreshPromise) return ui.repositoryRefreshPromise;
|
||||
ui.repositoryRefreshPromise = (async () => {
|
||||
let result;
|
||||
while (ui.repositoryRefreshRequest) {
|
||||
const request = ui.repositoryRefreshRequest;
|
||||
ui.repositoryRefreshRequest = null;
|
||||
result = await performRepositoryRefresh(request.withLoader, request.silent);
|
||||
}
|
||||
return result;
|
||||
})();
|
||||
try {
|
||||
return await ui.repositoryRefreshPromise;
|
||||
} finally {
|
||||
ui.repositoryRefreshPromise = null;
|
||||
}
|
||||
}
|
||||
|
||||
async function performRepositoryRefresh(withLoader = true, silent = false) {
|
||||
if (withLoader) setLoading(true, "Refreshing Local → Gitea → Server state…");
|
||||
try {
|
||||
const selectedId = ui.selectedRepoId;
|
||||
ui.repositories = await window.forgeflow.refreshRepositories();
|
||||
ui.repositories = await window.forgeflow.refreshRepositories({ force: withLoader });
|
||||
ui.refreshError = null;
|
||||
const staleRepository = ui.repositories.find(
|
||||
(repository) => repository.remoteStale,
|
||||
@@ -488,6 +514,25 @@ async function refreshActiveOperations(showErrors = true) {
|
||||
}
|
||||
|
||||
async function refreshDeploymentTruth(showErrors = false) {
|
||||
ui.deploymentTruthRequest = { showErrors: ui.deploymentTruthRequest?.showErrors === true || showErrors };
|
||||
if (ui.deploymentTruthPromise) return ui.deploymentTruthPromise;
|
||||
ui.deploymentTruthPromise = (async () => {
|
||||
let result;
|
||||
while (ui.deploymentTruthRequest) {
|
||||
const request = ui.deploymentTruthRequest;
|
||||
ui.deploymentTruthRequest = null;
|
||||
result = await performDeploymentTruthRefresh(request.showErrors);
|
||||
}
|
||||
return result;
|
||||
})();
|
||||
try {
|
||||
return await ui.deploymentTruthPromise;
|
||||
} finally {
|
||||
ui.deploymentTruthPromise = null;
|
||||
}
|
||||
}
|
||||
|
||||
async function performDeploymentTruthRefresh(showErrors = false) {
|
||||
let discovery = [];
|
||||
try {
|
||||
discovery = (await window.forgeflow.discoverServerDeployments?.()) || [];
|
||||
@@ -516,8 +561,11 @@ async function refreshDeploymentTruth(showErrors = false) {
|
||||
);
|
||||
if (!targets.length) return { checked: 0, failed: 0, discovery };
|
||||
|
||||
const inventoryRefreshedProfiles = new Set(discovery.flatMap((server) => server.refreshedProfileIds || []));
|
||||
const pendingTargets = targets.filter(({ profile }) => !inventoryRefreshedProfiles.has(profile.id));
|
||||
|
||||
const failures = [];
|
||||
const queue = [...targets];
|
||||
const queue = [...pendingTargets];
|
||||
const workers = Array.from(
|
||||
{ length: Math.min(3, queue.length) },
|
||||
async () => {
|
||||
@@ -547,7 +595,7 @@ async function refreshDeploymentTruth(showErrors = false) {
|
||||
"error",
|
||||
);
|
||||
}
|
||||
return { checked: targets.length, failed: failures.length, discovery };
|
||||
return { checked: targets.length, reusedInventory: targets.length - pendingTargets.length, failed: failures.length, discovery };
|
||||
}
|
||||
|
||||
function selectRepository(id, shouldRender = true) {
|
||||
|
||||
Reference in New Issue
Block a user