Skip to content

Commit 8afe5e1

Browse files
committed
fix(scraper): deduplicate identical term jobs for courseOfferings
1 parent efb5038 commit 8afe5e1

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

apps/scraper/src/index.ts

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -106,11 +106,11 @@ export default {
106106
`Cronjob: Scraping flags - current: ${isScrapeCurrent}, next: ${isScrapeNext}`,
107107
);
108108

109-
// Collect terms to scrape
110-
const termsToScrape: Array<{
111-
term: "spring" | "summer" | "fall" | "j-term";
112-
year: number;
113-
}> = [];
109+
// Collect unique terms to scrape using a Map to deduplicate
110+
const termsMap = new Map<
111+
string,
112+
{ term: "spring" | "summer" | "fall" | "j-term"; year: number }
113+
>();
114114

115115
if (isScrapeCurrent) {
116116
const currentTerm = (await convex.getAppConfig({
@@ -119,7 +119,8 @@ export default {
119119
const currentYearStr = await convex.getAppConfig({ key: "current_year" });
120120
if (currentYearStr) {
121121
const currentYear = Number.parseInt(currentYearStr, 10);
122-
termsToScrape.push({ term: currentTerm, year: currentYear });
122+
const key = `${currentTerm}-${currentYear}`;
123+
termsMap.set(key, { term: currentTerm, year: currentYear });
123124
}
124125
}
125126

@@ -132,10 +133,13 @@ export default {
132133
const nextYearStr = await convex.getAppConfig({ key: "next_year" });
133134
if (nextYearStr) {
134135
const nextYear = Number.parseInt(nextYearStr, 10);
135-
termsToScrape.push({ term: nextTerm, year: nextYear });
136+
const key = `${nextTerm}-${nextYear}`;
137+
termsMap.set(key, { term: nextTerm, year: nextYear });
136138
}
137139
}
138140

141+
const termsToScrape = Array.from(termsMap.values());
142+
139143
// Trigger course offerings discovery for each enabled term
140144
const courseOfferingsUrl = new URL(env.SCRAPING_BASE_URL).toString();
141145

0 commit comments

Comments
 (0)