fix: dedupe company skill inventory refreshes
Co-Authored-By: Paperclip <noreply@paperclip.ing>
This commit is contained in:
parent
ac376d0e5e
commit
a339b488ae
1 changed files with 21 additions and 2 deletions
|
|
@ -99,6 +99,8 @@ type RuntimeSkillEntryOptions = {
|
||||||
materializeMissing?: boolean;
|
materializeMissing?: boolean;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const skillInventoryRefreshPromises = new Map<string, Promise<void>>();
|
||||||
|
|
||||||
const PROJECT_SCAN_DIRECTORY_ROOTS = [
|
const PROJECT_SCAN_DIRECTORY_ROOTS = [
|
||||||
"skills",
|
"skills",
|
||||||
"skills/.curated",
|
"skills/.curated",
|
||||||
|
|
@ -1474,8 +1476,25 @@ export function companySkillService(db: Db) {
|
||||||
}
|
}
|
||||||
|
|
||||||
async function ensureSkillInventoryCurrent(companyId: string) {
|
async function ensureSkillInventoryCurrent(companyId: string) {
|
||||||
await ensureBundledSkills(companyId);
|
const existingRefresh = skillInventoryRefreshPromises.get(companyId);
|
||||||
await pruneMissingLocalPathSkills(companyId);
|
if (existingRefresh) {
|
||||||
|
await existingRefresh;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const refreshPromise = (async () => {
|
||||||
|
await ensureBundledSkills(companyId);
|
||||||
|
await pruneMissingLocalPathSkills(companyId);
|
||||||
|
})();
|
||||||
|
|
||||||
|
skillInventoryRefreshPromises.set(companyId, refreshPromise);
|
||||||
|
try {
|
||||||
|
await refreshPromise;
|
||||||
|
} finally {
|
||||||
|
if (skillInventoryRefreshPromises.get(companyId) === refreshPromise) {
|
||||||
|
skillInventoryRefreshPromises.delete(companyId);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function list(companyId: string): Promise<CompanySkillListItem[]> {
|
async function list(companyId: string): Promise<CompanySkillListItem[]> {
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue