mirror of
https://github.com/l0ng-ai/openidea.git
synced 2026-11-24 16:04:21 +00:00
A metadata reply that arrived after its data source was deactivated, deleted, edited or after a project switch could bring back the Connected indicator and the cleared schemas, tables, columns or completion, and an obsolete chain could issue further requests. Requests now carry project / source / target lifetimes (requests.ts); forget() starts a new lifetime, and late replies, introspection steps and follow-up requests of an ended lifetime are dropped. Completed writes keep their result but no longer revive an old connection. Co-authored-by: LunarFeller <269972968+LunarFeller@users.noreply.github.com>
36 lines
1.0 KiB
TypeScript
36 lines
1.0 KiB
TypeScript
import { useProject } from "@/platform/project";
|
|
import { splitTarget } from "./model";
|
|
|
|
let projectGeneration = 0;
|
|
const generations = new Map<string, object>();
|
|
|
|
useProject.subscribe((state, previous) => {
|
|
if (state.project?.root === previous.project?.root) return;
|
|
projectGeneration++;
|
|
generations.clear();
|
|
});
|
|
|
|
function generation(id: string): object {
|
|
let value = generations.get(id);
|
|
if (!value) generations.set(id, (value = {}));
|
|
return value;
|
|
}
|
|
|
|
/** A return to the same project or target is a new lifetime, too. */
|
|
export function projectRequest(): () => boolean {
|
|
const project = projectGeneration;
|
|
return () => project === projectGeneration;
|
|
}
|
|
|
|
export function databaseRequest(id: string): () => boolean {
|
|
const project = projectRequest();
|
|
const sourceId = splitTarget(id).id;
|
|
const source = generation(sourceId);
|
|
const target = generation(id);
|
|
return () => project() && generations.get(sourceId) === source && generations.get(id) === target;
|
|
}
|
|
|
|
export function invalidateDatabaseRequests(id: string) {
|
|
generations.set(id, {});
|
|
}
|