fix(skills): simplify source locator collection; remove redundant key derivation

- Use Set<string> instead of Map for tracking unique source locators
- Remove dead skillsAtSource destructuring from loop
- Remove redundant deriveCanonicalSkillKey call (already set by readUrlSkillImports)
- Invert slug check to continue guard for cleaner flow

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-04-11 08:07:36 -04:00
committed by Pawla Abdul (Bot)
parent aed1a886a9
commit a77fc31dc1
+9 -16
View File
@@ -2017,28 +2017,21 @@ export function companySkillService(db: Db) {
}
// Re-scan GitHub/sks_sh sources to pick up newly added skills
const existingSkills = acceptedSkills;
const sourceByLocator = new Map<string, CompanySkill[]>();
for (const skill of existingSkills) {
const sourceLocators = new Set<string>();
for (const skill of acceptedSkills) {
if (skill.sourceType !== "github" && skill.sourceType !== "skills_sh") continue;
const locator = skill.sourceLocator ?? "";
if (!locator) continue;
if (!sourceByLocator.has(locator)) sourceByLocator.set(locator, []);
sourceByLocator.get(locator)!.push(skill);
if (locator) sourceLocators.add(locator);
}
for (const [sourceLocator, skillsAtSource] of sourceByLocator) {
for (const sourceLocator of sourceLocators) {
try {
const result = await readUrlSkillImports(companyId, sourceLocator, null);
for (const nextSkill of result.skills) {
const existing = acceptedSkills.find((s) => s.slug === nextSkill.slug);
if (!existing) {
// New skill discovered — derive key and upsert
nextSkill.key = deriveCanonicalSkillKey(companyId, nextSkill);
const persisted = (await upsertImportedSkills(companyId, [nextSkill]))[0];
if (persisted) {
imported.push(persisted);
upsertAcceptedSkill(persisted);
}
if (acceptedSkills.some((s) => s.slug === nextSkill.slug)) continue;
const persisted = (await upsertImportedSkills(companyId, [nextSkill]))[0];
if (persisted) {
imported.push(persisted);
upsertAcceptedSkill(persisted);
}
}
} catch {