fix(plugin-center): renew coalesced load intent
This commit is contained in:
@@ -44,6 +44,7 @@ export function createCodingPluginsStore(overrides: Partial<Dependencies> = {}):
|
||||
removeProject: removeDataServiceProject, ...overrides,
|
||||
};
|
||||
const flights = new Map<string, Promise<void>>();
|
||||
const loadFlightGenerations = new Map<string, number>();
|
||||
const pendingCounts = new Map<string, number>();
|
||||
const projectEpochs = new Map<string, number>();
|
||||
let loadGeneration = 0;
|
||||
@@ -67,7 +68,10 @@ export function createCodingPluginsStore(overrides: Partial<Dependencies> = {}):
|
||||
pendingCounts.set(pendingKey, pendingCount);
|
||||
let flight: Promise<void>;
|
||||
flight = run().finally(() => {
|
||||
if (flights.get(key) === flight) flights.delete(key);
|
||||
if (flights.get(key) === flight) {
|
||||
flights.delete(key);
|
||||
loadFlightGenerations.delete(key);
|
||||
}
|
||||
const remaining = (pendingCounts.get(pendingKey) ?? 1) - 1;
|
||||
if (remaining > 0) {
|
||||
pendingCounts.set(pendingKey, remaining);
|
||||
@@ -92,8 +96,11 @@ export function createCodingPluginsStore(overrides: Partial<Dependencies> = {}):
|
||||
const pendingKey = `load:${projectId}`;
|
||||
const key = `${pendingKey}:${epoch}`;
|
||||
const existing = flights.get(key);
|
||||
if (existing) return existing;
|
||||
const generation = ++loadGeneration;
|
||||
if (existing) {
|
||||
loadFlightGenerations.set(key, ++loadGeneration);
|
||||
return existing;
|
||||
}
|
||||
loadFlightGenerations.set(key, ++loadGeneration);
|
||||
return operation(key, async () => {
|
||||
set({ loadState: 'loading', error: null });
|
||||
try {
|
||||
@@ -104,11 +111,11 @@ export function createCodingPluginsStore(overrides: Partial<Dependencies> = {}):
|
||||
const result = await deps.inspectDataService();
|
||||
if (result.success && result.data) dataService = result.data;
|
||||
}
|
||||
if (generation === loadGeneration && epoch === projectEpoch(projectId)) {
|
||||
if (loadFlightGenerations.get(key) === loadGeneration && epoch === projectEpoch(projectId)) {
|
||||
set({ projectId, projection, dataService, loadState: 'ready', error: null });
|
||||
}
|
||||
} catch (error) {
|
||||
if (generation === loadGeneration && epoch === projectEpoch(projectId)) {
|
||||
if (loadFlightGenerations.get(key) === loadGeneration && epoch === projectEpoch(projectId)) {
|
||||
set({ loadState: 'error', error: error instanceof Error ? error.message : String(error) });
|
||||
}
|
||||
throw error;
|
||||
|
||||
Reference in New Issue
Block a user