Skip to content

Supercharge your AI agents with data from the web and beyond. Building the library for superintelligence. 🔥

Nick: crawl fixes

Nicolas52806807a183
diff --git a/apps/api/src/controllers/v1/crawl.ts b/apps/api/src/controllers/v1/crawl.ts
index aaf33f293..2195913fe 100644
--- a/apps/api/src/controllers/v1/crawl.ts
+++ b/apps/api/src/controllers/v1/crawl.ts
@@ -129,7 +129,7 @@ export async function crawlController(
priority: 20,
},
};
- });
+ })
await lockURLs(
id,
diff --git a/apps/api/src/lib/crawl-redis.ts b/apps/api/src/lib/crawl-redis.ts
index ba7487bdf..68087993a 100644
--- a/apps/api/src/lib/crawl-redis.ts
+++ b/apps/api/src/lib/crawl-redis.ts
@@ -158,11 +158,22 @@ export async function lockURL(id: string, sc: StoredCrawl, url: string): Promise
/// NOTE: does not check limit. only use if limit is checked beforehand e.g. with sitemap
export async function lockURLs(id: string, sc: StoredCrawl, urls: string[]): Promise<boolean> {
- urls = urls.map(url => {
- return normalizeURL(url, sc);
- });
-
- const res = (await redisConnection.sadd("crawl:" + id + ":visited", ...urls)) !== 0
+ urls = urls.map(url => normalizeURL(url, sc));
+
+ // Add to visited_unique set
+ await redisConnection.sadd("crawl:" + id + ":visited_unique", ...urls);
+ await redisConnection.expire("crawl:" + id + ":visited_unique", 24 * 60 * 60, "NX");
+
+ let res: boolean;
+ if (!sc.crawlerOptions?.deduplicateSimilarURLs) {
+ const x = await redisConnection.sadd("crawl:" + id + ":visited", ...urls);
+ res = x === urls.length;
+ } else {
+ const allPermutations = urls.flatMap(url => generateURLPermutations(url).map(x => x.href));
+ const x = await redisConnection.sadd("crawl:" + id + ":visited", ...allPermutations);
+ res = x === allPermutations.length;
+ }
+
await redisConnection.expire("crawl:" + id + ":visited", 24 * 60 * 60, "NX");
return res;
}