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
+5 -12
View File
@@ -2017,30 +2017,23 @@ export function companySkillService(db: Db) {
} }
// Re-scan GitHub/sks_sh sources to pick up newly added skills // Re-scan GitHub/sks_sh sources to pick up newly added skills
const existingSkills = acceptedSkills; const sourceLocators = new Set<string>();
const sourceByLocator = new Map<string, CompanySkill[]>(); for (const skill of acceptedSkills) {
for (const skill of existingSkills) {
if (skill.sourceType !== "github" && skill.sourceType !== "skills_sh") continue; if (skill.sourceType !== "github" && skill.sourceType !== "skills_sh") continue;
const locator = skill.sourceLocator ?? ""; const locator = skill.sourceLocator ?? "";
if (!locator) continue; if (locator) sourceLocators.add(locator);
if (!sourceByLocator.has(locator)) sourceByLocator.set(locator, []);
sourceByLocator.get(locator)!.push(skill);
} }
for (const [sourceLocator, skillsAtSource] of sourceByLocator) { for (const sourceLocator of sourceLocators) {
try { try {
const result = await readUrlSkillImports(companyId, sourceLocator, null); const result = await readUrlSkillImports(companyId, sourceLocator, null);
for (const nextSkill of result.skills) { for (const nextSkill of result.skills) {
const existing = acceptedSkills.find((s) => s.slug === nextSkill.slug); if (acceptedSkills.some((s) => s.slug === nextSkill.slug)) continue;
if (!existing) {
// New skill discovered — derive key and upsert
nextSkill.key = deriveCanonicalSkillKey(companyId, nextSkill);
const persisted = (await upsertImportedSkills(companyId, [nextSkill]))[0]; const persisted = (await upsertImportedSkills(companyId, [nextSkill]))[0];
if (persisted) { if (persisted) {
imported.push(persisted); imported.push(persisted);
upsertAcceptedSkill(persisted); upsertAcceptedSkill(persisted);
} }
} }
}
} catch { } catch {
// Best-effort: don't fail the whole scan if one source fails // Best-effort: don't fail the whole scan if one source fails
warnings.push(`Could not re-scan source ${sourceLocator} — skipping.`); warnings.push(`Could not re-scan source ${sourceLocator} — skipping.`);