@nitpicker/crawler 0.22.0 → 0.22.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -7,7 +7,7 @@ import type { Knex } from 'knex';
|
|
|
7
7
|
* setSkippedPage / setExternalPage / outright setPage success or failure.
|
|
8
8
|
*
|
|
9
9
|
* `pending` is intentionally STRICT — not "every `scraped = 0` row".
|
|
10
|
-
*
|
|
10
|
+
* Four filters apply:
|
|
11
11
|
*
|
|
12
12
|
* 1. `scraped = 0` — work still incomplete.
|
|
13
13
|
* 2. `is_external = 0` — only in-scope work. External URLs go through a
|
|
@@ -36,6 +36,46 @@ import type { Knex } from 'knex';
|
|
|
36
36
|
* URL came from the operator's URL list (no anchor referrer) and
|
|
37
37
|
* `resetFailedPages` puts it back at `scraped = 0`. Without this
|
|
38
38
|
* clause those legitimate retries would be dropped on resume.
|
|
39
|
+
* 4. **Confirmed same-cluster trap exclusion** (issue #350): a row whose
|
|
40
|
+
* URL shape (`computeShapeKey`) matches a `dedupe_cap_events.shape_key`
|
|
41
|
+
* already recorded in this archive is dropped, UNLESS its `source` is
|
|
42
|
+
* `'inventory-seed'` (an operator-listed URL, not an anchor-discovered
|
|
43
|
+
* one — the same "explicit URL survives cap" carve-out `resetPagesByUrls`
|
|
44
|
+
* gives `--recrawl`). NOT the same as `resetFailedPages`'s own
|
|
45
|
+
* same-shape exclusion, which drops a matching candidate regardless of
|
|
46
|
+
* `source` — a `scraped=1, status=-1` inventory-seed row of a
|
|
47
|
+
* confirmed-capped shape is therefore excluded there too and never
|
|
48
|
+
* resets to `scraped=0` for `--retry-failed` to pick back up. That
|
|
49
|
+
* asymmetry pre-dates this filter and is unrelated to it (out of scope
|
|
50
|
+
* here): this filter only decides what `getCrawlingState` reports as
|
|
51
|
+
* `pending`, never whether a `scraped=1` row gets reset in the first
|
|
52
|
+
* place.
|
|
53
|
+
*
|
|
54
|
+
* Why this is needed: `--dedupe-cap`'s enqueue gate (`crawler.ts`'s
|
|
55
|
+
* `addUrl` closure) only stops a capped shape's anchor from being
|
|
56
|
+
* ADDED TO THE QUEUE in memory — it does not stop `replaceAnchorEdges`
|
|
57
|
+
* (`update-page.ts`) from writing a `scraped = 0` row for that same
|
|
58
|
+
* anchor (post-hoc marking, `content_items.dedupe_cap_event_id`,
|
|
59
|
+
* deliberately needs that row to exist). Before this filter, such a
|
|
60
|
+
* row still satisfied filter 3 (it has an anchor referrer) and entered
|
|
61
|
+
* `pending`, so `CrawlerOrchestrator#crawlUntilPendingClears`'s
|
|
62
|
+
* auto-retry loop (and any `--resume`/`--retry-failed`/`--append`) would
|
|
63
|
+
* requeue it — `Crawler#resume`'s `LinkList#resume` has no cap gate of
|
|
64
|
+
* its own — actually fetch the trap page, and its anchors would create
|
|
65
|
+
* a fresh batch of same-shape `scraped = 0` rows. Pending never shrank,
|
|
66
|
+
* so the loop ended in `PendingUrlsRemainError('no-progress')` even
|
|
67
|
+
* though nothing was actually wrong with the target site.
|
|
68
|
+
*
|
|
69
|
+
* Why not skip the row instead of merely omitting it from `pending`:
|
|
70
|
+
* this function is read-only — leaving `is_skipped`/`skip_reason`
|
|
71
|
+
* unset keeps `dedupe_cap_event_id` backfill (`viewer-build`) as the
|
|
72
|
+
* single place that judges a row "capped", matching the archive's
|
|
73
|
+
* existing dedupe-cap post-hoc-marking pattern rather than adding a
|
|
74
|
+
* second one here.
|
|
75
|
+
*
|
|
76
|
+
* A row whose shape cannot be computed (`computeShapeKey` returns
|
|
77
|
+
* `null`) stays in `pending` — no signal either way, same
|
|
78
|
+
* err-on-the-side-of-retrying choice `resetFailedPages` makes.
|
|
39
79
|
*
|
|
40
80
|
* The defensive shape is on purpose: the data source can drift into
|
|
41
81
|
* anomalous states under interruption, but the reader must never throw
|
|
@@ -62,8 +102,8 @@ import type { Knex } from 'knex';
|
|
|
62
102
|
* methods carry.
|
|
63
103
|
* @param knex - Knex query builder connected to the archive DB.
|
|
64
104
|
* @returns An object with `scraped` (completed URLs), `pending` (the
|
|
65
|
-
* strict set of in-scope, anchor-referenced, unfinished
|
|
66
|
-
* `pendingMetadataOnly` (the subset of `pending` whose
|
|
105
|
+
* strict set of in-scope, anchor-referenced, unfinished, non-capped
|
|
106
|
+
* URLs), and `pendingMetadataOnly` (the subset of `pending` whose
|
|
67
107
|
* `content_items.is_metadata_only` was persisted as `1` — see
|
|
68
108
|
* `replaceAnchorEdges`/`resolveContentItemId`). Callers that resume a
|
|
69
109
|
* crawl (`Crawler#resume` → `LinkList#resume`) pass this subset through
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { computeShapeKey } from '../../../../crawler/dedupe/compute-shape-key.js';
|
|
2
|
+
import { listDedupeCapShapeKeys } from '../../dedupe-cap/list-dedupe-cap-shape-keys.js';
|
|
1
3
|
/**
|
|
2
4
|
* Retrieves the current crawling state by listing scraped and pending URLs.
|
|
3
5
|
*
|
|
@@ -6,7 +8,7 @@
|
|
|
6
8
|
* setSkippedPage / setExternalPage / outright setPage success or failure.
|
|
7
9
|
*
|
|
8
10
|
* `pending` is intentionally STRICT — not "every `scraped = 0` row".
|
|
9
|
-
*
|
|
11
|
+
* Four filters apply:
|
|
10
12
|
*
|
|
11
13
|
* 1. `scraped = 0` — work still incomplete.
|
|
12
14
|
* 2. `is_external = 0` — only in-scope work. External URLs go through a
|
|
@@ -35,6 +37,46 @@
|
|
|
35
37
|
* URL came from the operator's URL list (no anchor referrer) and
|
|
36
38
|
* `resetFailedPages` puts it back at `scraped = 0`. Without this
|
|
37
39
|
* clause those legitimate retries would be dropped on resume.
|
|
40
|
+
* 4. **Confirmed same-cluster trap exclusion** (issue #350): a row whose
|
|
41
|
+
* URL shape (`computeShapeKey`) matches a `dedupe_cap_events.shape_key`
|
|
42
|
+
* already recorded in this archive is dropped, UNLESS its `source` is
|
|
43
|
+
* `'inventory-seed'` (an operator-listed URL, not an anchor-discovered
|
|
44
|
+
* one — the same "explicit URL survives cap" carve-out `resetPagesByUrls`
|
|
45
|
+
* gives `--recrawl`). NOT the same as `resetFailedPages`'s own
|
|
46
|
+
* same-shape exclusion, which drops a matching candidate regardless of
|
|
47
|
+
* `source` — a `scraped=1, status=-1` inventory-seed row of a
|
|
48
|
+
* confirmed-capped shape is therefore excluded there too and never
|
|
49
|
+
* resets to `scraped=0` for `--retry-failed` to pick back up. That
|
|
50
|
+
* asymmetry pre-dates this filter and is unrelated to it (out of scope
|
|
51
|
+
* here): this filter only decides what `getCrawlingState` reports as
|
|
52
|
+
* `pending`, never whether a `scraped=1` row gets reset in the first
|
|
53
|
+
* place.
|
|
54
|
+
*
|
|
55
|
+
* Why this is needed: `--dedupe-cap`'s enqueue gate (`crawler.ts`'s
|
|
56
|
+
* `addUrl` closure) only stops a capped shape's anchor from being
|
|
57
|
+
* ADDED TO THE QUEUE in memory — it does not stop `replaceAnchorEdges`
|
|
58
|
+
* (`update-page.ts`) from writing a `scraped = 0` row for that same
|
|
59
|
+
* anchor (post-hoc marking, `content_items.dedupe_cap_event_id`,
|
|
60
|
+
* deliberately needs that row to exist). Before this filter, such a
|
|
61
|
+
* row still satisfied filter 3 (it has an anchor referrer) and entered
|
|
62
|
+
* `pending`, so `CrawlerOrchestrator#crawlUntilPendingClears`'s
|
|
63
|
+
* auto-retry loop (and any `--resume`/`--retry-failed`/`--append`) would
|
|
64
|
+
* requeue it — `Crawler#resume`'s `LinkList#resume` has no cap gate of
|
|
65
|
+
* its own — actually fetch the trap page, and its anchors would create
|
|
66
|
+
* a fresh batch of same-shape `scraped = 0` rows. Pending never shrank,
|
|
67
|
+
* so the loop ended in `PendingUrlsRemainError('no-progress')` even
|
|
68
|
+
* though nothing was actually wrong with the target site.
|
|
69
|
+
*
|
|
70
|
+
* Why not skip the row instead of merely omitting it from `pending`:
|
|
71
|
+
* this function is read-only — leaving `is_skipped`/`skip_reason`
|
|
72
|
+
* unset keeps `dedupe_cap_event_id` backfill (`viewer-build`) as the
|
|
73
|
+
* single place that judges a row "capped", matching the archive's
|
|
74
|
+
* existing dedupe-cap post-hoc-marking pattern rather than adding a
|
|
75
|
+
* second one here.
|
|
76
|
+
*
|
|
77
|
+
* A row whose shape cannot be computed (`computeShapeKey` returns
|
|
78
|
+
* `null`) stays in `pending` — no signal either way, same
|
|
79
|
+
* err-on-the-side-of-retrying choice `resetFailedPages` makes.
|
|
38
80
|
*
|
|
39
81
|
* The defensive shape is on purpose: the data source can drift into
|
|
40
82
|
* anomalous states under interruption, but the reader must never throw
|
|
@@ -61,8 +103,8 @@
|
|
|
61
103
|
* methods carry.
|
|
62
104
|
* @param knex - Knex query builder connected to the archive DB.
|
|
63
105
|
* @returns An object with `scraped` (completed URLs), `pending` (the
|
|
64
|
-
* strict set of in-scope, anchor-referenced, unfinished
|
|
65
|
-
* `pendingMetadataOnly` (the subset of `pending` whose
|
|
106
|
+
* strict set of in-scope, anchor-referenced, unfinished, non-capped
|
|
107
|
+
* URLs), and `pendingMetadataOnly` (the subset of `pending` whose
|
|
66
108
|
* `content_items.is_metadata_only` was persisted as `1` — see
|
|
67
109
|
* `replaceAnchorEdges`/`resolveContentItemId`). Callers that resume a
|
|
68
110
|
* crawl (`Crawler#resume` → `LinkList#resume`) pass this subset through
|
|
@@ -77,7 +119,7 @@ export async function getCrawlingState(knex) {
|
|
|
77
119
|
.where('content_items.scraped', 1);
|
|
78
120
|
const scraped = $scraped.map(ex);
|
|
79
121
|
const $pending = await knex
|
|
80
|
-
.select('ur.url as url', 'ci.is_metadata_only as isMetadataOnly')
|
|
122
|
+
.select('ur.url as url', 'ci.is_metadata_only as isMetadataOnly', 'ci.source as source')
|
|
81
123
|
.from({ ci: 'content_items' })
|
|
82
124
|
.join({ ur: 'url_refs' }, 'ur.id', 'ci.url_id')
|
|
83
125
|
.where('ci.scraped', 0)
|
|
@@ -96,8 +138,21 @@ export async function getCrawlingState(knex) {
|
|
|
96
138
|
.whereRaw('anchor_edges.href_page_id = ci.id');
|
|
97
139
|
}).orWhereNot('ci.source', 'crawled');
|
|
98
140
|
});
|
|
99
|
-
|
|
100
|
-
|
|
141
|
+
// Confirmed same-cluster trap exclusion (filter 4, see this function's
|
|
142
|
+
// JSDoc) — an archive with no recorded cap events behaves exactly as
|
|
143
|
+
// before this filter existed (`cappedShapeKeys.size === 0` short-circuits
|
|
144
|
+
// to a no-op, same guard `resetFailedPages` uses).
|
|
145
|
+
const cappedShapeKeys = new Set(await listDedupeCapShapeKeys(knex));
|
|
146
|
+
const $notCapped = cappedShapeKeys.size === 0
|
|
147
|
+
? $pending
|
|
148
|
+
: $pending.filter((row) => {
|
|
149
|
+
if (row.source === 'inventory-seed')
|
|
150
|
+
return true;
|
|
151
|
+
const shapeKey = computeShapeKey(row.url);
|
|
152
|
+
return shapeKey === null || !cappedShapeKeys.has(shapeKey);
|
|
153
|
+
});
|
|
154
|
+
const pending = $notCapped.map(ex);
|
|
155
|
+
const pendingMetadataOnly = $notCapped.filter((r) => r.isMetadataOnly === 1).map(ex);
|
|
101
156
|
return {
|
|
102
157
|
scraped,
|
|
103
158
|
pending,
|
|
@@ -294,8 +294,16 @@ async function readSourceByUrl(trx, caches, url) {
|
|
|
294
294
|
* `processAnchors` (`handle-scrape-end.ts`) decides whether to queue the
|
|
295
295
|
* anchor for a full or metadata-only scrape: `!recursive || isExternal`.
|
|
296
296
|
* Both `recursive` and a given URL's `isExternal` are constant for the
|
|
297
|
-
*
|
|
298
|
-
*
|
|
297
|
+
* duration of one `CrawlerOrchestrator#crawling()` invocation (this is a
|
|
298
|
+
* pure recomputation of that call's own decision, not a second source of
|
|
299
|
+
* truth, #369) — NOT necessarily across the whole session:
|
|
300
|
+
* `#crawlUntilPendingClears`'s auto-retry loop (issue #350) always
|
|
301
|
+
* re-invokes `crawling([], { recursive: false, isRetryContinuation: true })`
|
|
302
|
+
* for a retry round regardless of the session's original `recursive`
|
|
303
|
+
* value, so the SAME URL anchored again during a retry round can compute
|
|
304
|
+
* a different `is_metadata_only` verdict than it did on the original
|
|
305
|
+
* pass. `resolveContentItemId`'s ratchet lets the later call's opinion
|
|
306
|
+
* win, same as it does for any other repeat discovery.
|
|
299
307
|
*/
|
|
300
308
|
async function replaceAnchorEdges(trx, caches, pageId, page, anchorLineageSource, recursive) {
|
|
301
309
|
if (page.anchorList.length === 0) {
|
|
@@ -773,6 +773,13 @@ export class CrawlerOrchestrator extends EventEmitter {
|
|
|
773
773
|
* that a final attempt which is both exhausted AND made no progress
|
|
774
774
|
* reports as `'exhausted'` — the more actionable of the two (it tells
|
|
775
775
|
* the operator the budget, not just that this one attempt stalled).
|
|
776
|
+
* `getCrawlingState()`'s "Confirmed same-cluster trap exclusion"
|
|
777
|
+
* filter (issue #350) keeps a `--dedupe-cap`-confirmed shape's own
|
|
778
|
+
* never-scraped descendants out of `pending` in the first place, so
|
|
779
|
+
* `pending` genuinely converging to 0 is no longer blocked by that
|
|
780
|
+
* shape — a `'no-progress'` or `'exhausted'` result here now points
|
|
781
|
+
* at a real, currently-unresolvable fetch failure (network/host),
|
|
782
|
+
* not at a same-cluster trap the cap already confirmed.
|
|
776
783
|
*
|
|
777
784
|
* Each retry attempt re-reads `getCrawlingState()` and
|
|
778
785
|
* `getResourceUrlList()` in full — the same cost `retryFailed`/`resume`/
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nitpicker/crawler",
|
|
3
|
-
"version": "0.22.
|
|
3
|
+
"version": "0.22.2",
|
|
4
4
|
"description": "Web crawler engine with headless browser rendering and archive storage",
|
|
5
5
|
"author": "D-ZERO",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -51,5 +51,5 @@
|
|
|
51
51
|
"@types/tar": "7.0.87",
|
|
52
52
|
"@types/unzipper": "0.10.11"
|
|
53
53
|
},
|
|
54
|
-
"gitHead": "
|
|
54
|
+
"gitHead": "27db72abdebd19dc6f83a1b5087d73d8b574f229"
|
|
55
55
|
}
|