Skip to content

Commit a3dd3b6

Browse files
committed
quick fix
1 parent 937773c commit a3dd3b6

500 files changed

Lines changed: 835898 additions & 27 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
204 Bytes
Binary file not shown.
7.27 KB
Binary file not shown.
16 KB
Binary file not shown.
8.82 KB
Binary file not shown.
2.72 KB
Binary file not shown.
5.95 KB
Binary file not shown.

‎backend/crawler.py‎

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,8 @@ def __init__(self, queue_maxsize: int = 1000, worker_count: int = 5) -> None:
8282
self.worker_count = worker_count
8383
self.jobs: Dict[str, CrawlContext] = {}
8484
self.global_stats = CrawlStats(queue_max=queue_maxsize)
85+
# Global visited set to avoid crawling the exact same URL across jobs.
86+
self.global_visited: Set[str] = set()
8587
self._lock = asyncio.Lock()
8688

8789
def register_job(self, job: CrawlJob) -> None:
@@ -130,11 +132,9 @@ async def _worker(self, ctx: CrawlContext) -> None:
130132
ctx.queue.task_done()
131133
continue
132134

133-
if url in ctx.visited:
135+
if not await self._try_mark_visited(ctx, url):
134136
ctx.queue.task_done()
135137
continue
136-
137-
ctx.visited.add(url)
138138
await self._respect_rate_limit(ctx)
139139
html_text = await fetch_html(url)
140140

@@ -147,7 +147,7 @@ async def _worker(self, ctx: CrawlContext) -> None:
147147
if html_text and depth < job.max_depth:
148148
links = extract_links(url, html_text)
149149
for link in links:
150-
if link in ctx.visited:
150+
if await self._already_visited(ctx, link):
151151
continue
152152
try:
153153
ctx.queue.put_nowait((link, depth + 1, origin_url))
@@ -173,6 +173,19 @@ async def _worker(self, ctx: CrawlContext) -> None:
173173
job.stats.backpressure_state = "idle"
174174
self.global_stats.backpressure_state = "idle"
175175

176+
async def _try_mark_visited(self, ctx: CrawlContext, url: str) -> bool:
177+
"""Mark a URL as visited for this job and globally, returning False if it was seen before."""
178+
async with self._lock:
179+
if url in ctx.visited or url in self.global_visited:
180+
return False
181+
ctx.visited.add(url)
182+
self.global_visited.add(url)
183+
return True
184+
185+
async def _already_visited(self, ctx: CrawlContext, url: str) -> bool:
186+
async with self._lock:
187+
return url in ctx.visited or url in self.global_visited
188+
176189
async def _respect_rate_limit(self, ctx: CrawlContext) -> None:
177190
min_interval = 1.0 / ctx.rate_limit_per_sec
178191
now = time.monotonic()

‎crawler.db‎

20 KB
Binary file not shown.

‎frontend/node_modules/.bin/esbuild‎

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎frontend/node_modules/.bin/loose-envify‎

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)