@nitpicker/crawler 0.22.2 → 0.24.0
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.
- package/lib/archive/archive.d.ts +13 -5
- package/lib/archive/archive.js +16 -7
- package/lib/archive/cache/extract-archive-to-cache.d.ts +6 -1
- package/lib/archive/cache/extract-archive-to-cache.js +13 -6
- package/lib/archive/create-adjunct-tables.d.ts +0 -7
- package/lib/archive/create-adjunct-tables.js +0 -50
- package/lib/archive/create-template-tables.d.ts +30 -0
- package/lib/archive/create-template-tables.js +95 -0
- package/lib/archive/database.d.ts +1 -1
- package/lib/archive/database.js +1 -1
- package/lib/archive/db-ops/config/get-config.d.ts +1 -1
- package/lib/archive/db-ops/config/get-config.js +2 -1
- package/lib/archive/db-ops/config/info-column-allowlist.js +1 -0
- package/lib/archive/db-ops/config/info-json-columns.js +1 -0
- package/lib/archive/db-ops/lifecycle/init.js +2 -0
- package/lib/archive/db-ops/templates/assign-template-labels.d.ts +60 -0
- package/lib/archive/db-ops/templates/assign-template-labels.js +187 -0
- package/lib/archive/db-ops/{analysis → templates}/replace-page-templates.d.ts +19 -3
- package/lib/archive/db-ops/templates/replace-page-templates.js +174 -0
- package/lib/archive/db-ops/{analysis → templates}/types.d.ts +38 -0
- package/lib/archive/init-schema.d.ts +5 -1
- package/lib/archive/init-schema.js +14 -2
- package/lib/archive/migrate-info-request-header-names.d.ts +16 -0
- package/lib/archive/migrate-info-request-header-names.js +35 -0
- package/lib/archive/test-utils/build-full-schema-test-db.d.ts +34 -0
- package/lib/archive/test-utils/build-full-schema-test-db.js +74 -0
- package/lib/archive/transfer/attach-source-database.d.ts +31 -0
- package/lib/archive/transfer/attach-source-database.js +40 -0
- package/lib/archive/transfer/build-split-config.d.ts +30 -0
- package/lib/archive/transfer/build-split-config.js +42 -0
- package/lib/archive/transfer/clear-replaced-page-rows.d.ts +20 -0
- package/lib/archive/transfer/clear-replaced-page-rows.js +57 -0
- package/lib/archive/transfer/concat-archives.d.ts +55 -0
- package/lib/archive/transfer/concat-archives.js +95 -0
- package/lib/archive/transfer/content-item-rank-sql.d.ts +21 -0
- package/lib/archive/transfer/content-item-rank-sql.js +23 -0
- package/lib/archive/transfer/copy-analysis-violations.d.ts +19 -0
- package/lib/archive/transfer/copy-analysis-violations.js +43 -0
- package/lib/archive/transfer/copy-anchor-edges.d.ts +28 -0
- package/lib/archive/transfer/copy-anchor-edges.js +42 -0
- package/lib/archive/transfer/copy-dictionaries-for-concat.d.ts +39 -0
- package/lib/archive/transfer/copy-dictionaries-for-concat.js +81 -0
- package/lib/archive/transfer/copy-dictionaries-for-split.d.ts +29 -0
- package/lib/archive/transfer/copy-dictionaries-for-split.js +235 -0
- package/lib/archive/transfer/copy-header-set-children.d.ts +27 -0
- package/lib/archive/transfer/copy-header-set-children.js +51 -0
- package/lib/archive/transfer/copy-image-items.d.ts +21 -0
- package/lib/archive/transfer/copy-image-items.js +62 -0
- package/lib/archive/transfer/copy-inventory-source-lists.d.ts +30 -0
- package/lib/archive/transfer/copy-inventory-source-lists.js +61 -0
- package/lib/archive/transfer/copy-journal-tables.d.ts +30 -0
- package/lib/archive/transfer/copy-journal-tables.js +56 -0
- package/lib/archive/transfer/copy-page-console-logs.d.ts +16 -0
- package/lib/archive/transfer/copy-page-console-logs.js +27 -0
- package/lib/archive/transfer/copy-page-html-blobs.d.ts +31 -0
- package/lib/archive/transfer/copy-page-html-blobs.js +43 -0
- package/lib/archive/transfer/copy-page-meta.d.ts +27 -0
- package/lib/archive/transfer/copy-page-meta.js +68 -0
- package/lib/archive/transfer/copy-page-template-clusters.d.ts +31 -0
- package/lib/archive/transfer/copy-page-template-clusters.js +56 -0
- package/lib/archive/transfer/copy-page-template-labels.d.ts +34 -0
- package/lib/archive/transfer/copy-page-template-labels.js +88 -0
- package/lib/archive/transfer/copy-resource-items.d.ts +29 -0
- package/lib/archive/transfer/copy-resource-items.js +89 -0
- package/lib/archive/transfer/copy-resource-ref-edges.d.ts +20 -0
- package/lib/archive/transfer/copy-resource-ref-edges.js +33 -0
- package/lib/archive/transfer/copy-simple-page-scoped-tables.d.ts +15 -0
- package/lib/archive/transfer/copy-simple-page-scoped-tables.js +34 -0
- package/lib/archive/transfer/count-external-pages-in-scope.d.ts +26 -0
- package/lib/archive/transfer/count-external-pages-in-scope.js +40 -0
- package/lib/archive/transfer/create-transfer-temp-tables.d.ts +30 -0
- package/lib/archive/transfer/create-transfer-temp-tables.js +59 -0
- package/lib/archive/transfer/dictionary-copy-specs.d.ts +32 -0
- package/lib/archive/transfer/dictionary-copy-specs.js +29 -0
- package/lib/archive/transfer/drop-transfer-temp-tables.d.ts +9 -0
- package/lib/archive/transfer/drop-transfer-temp-tables.js +18 -0
- package/lib/archive/transfer/flatten-redirect-chains.d.ts +44 -0
- package/lib/archive/transfer/flatten-redirect-chains.js +74 -0
- package/lib/archive/transfer/insert-content-items.d.ts +35 -0
- package/lib/archive/transfer/insert-content-items.js +116 -0
- package/lib/archive/transfer/list-transfer-columns.d.ts +35 -0
- package/lib/archive/transfer/list-transfer-columns.js +45 -0
- package/lib/archive/transfer/mark-in-scope-content-items.d.ts +31 -0
- package/lib/archive/transfer/mark-in-scope-content-items.js +54 -0
- package/lib/archive/transfer/merge-archive-configs.d.ts +51 -0
- package/lib/archive/transfer/merge-archive-configs.js +85 -0
- package/lib/archive/transfer/plan-content-items-for-concat.d.ts +33 -0
- package/lib/archive/transfer/plan-content-items-for-concat.js +51 -0
- package/lib/archive/transfer/plan-content-items-for-split.d.ts +42 -0
- package/lib/archive/transfer/plan-content-items-for-split.js +83 -0
- package/lib/archive/transfer/plan-resource-items.d.ts +40 -0
- package/lib/archive/transfer/plan-resource-items.js +69 -0
- package/lib/archive/transfer/quote-transfer-identifier.d.ts +18 -0
- package/lib/archive/transfer/quote-transfer-identifier.js +20 -0
- package/lib/archive/transfer/reclassify-resource-externality.d.ts +37 -0
- package/lib/archive/transfer/reclassify-resource-externality.js +66 -0
- package/lib/archive/transfer/remap-redirect-dest-ids.d.ts +34 -0
- package/lib/archive/transfer/remap-redirect-dest-ids.js +51 -0
- package/lib/archive/transfer/replace-content-items.d.ts +39 -0
- package/lib/archive/transfer/replace-content-items.js +83 -0
- package/lib/archive/transfer/simple-page-scoped-tables.d.ts +25 -0
- package/lib/archive/transfer/simple-page-scoped-tables.js +38 -0
- package/lib/archive/transfer/split-archive.d.ts +55 -0
- package/lib/archive/transfer/split-archive.js +98 -0
- package/lib/archive/transfer/transfer-action.d.ts +34 -0
- package/lib/archive/transfer/transfer-action.js +32 -0
- package/lib/archive/transfer/transfer-archive-rows.d.ts +65 -0
- package/lib/archive/transfer/transfer-archive-rows.js +158 -0
- package/lib/archive/transfer/transfer-dictionary-tables.d.ts +12 -0
- package/lib/archive/transfer/transfer-dictionary-tables.js +23 -0
- package/lib/archive/transfer/transfer-source-alias.d.ts +9 -0
- package/lib/archive/transfer/transfer-source-alias.js +9 -0
- package/lib/archive/transfer/types.d.ts +111 -0
- package/lib/archive/transfer/types.js +35 -0
- package/lib/archive/types.d.ts +10 -0
- package/lib/concat-source-transfer-phases.d.ts +10 -0
- package/lib/concat-source-transfer-phases.js +17 -0
- package/lib/crawler/apply-request-header-interception.d.ts +22 -0
- package/lib/crawler/apply-request-header-interception.js +28 -0
- package/lib/crawler/build-scope-map.d.ts +21 -0
- package/lib/crawler/build-scope-map.js +32 -0
- package/lib/crawler/crawler.js +34 -0
- package/lib/crawler/create-scoped-header-request-handler.d.ts +40 -0
- package/lib/crawler/create-scoped-header-request-handler.js +64 -0
- package/lib/crawler/create-strip-headers-on-redirect.d.ts +41 -0
- package/lib/crawler/create-strip-headers-on-redirect.js +67 -0
- package/lib/crawler/fetch-destination.d.ts +14 -0
- package/lib/crawler/fetch-destination.js +56 -9
- package/lib/crawler/fetch-robots-txt.d.ts +7 -0
- package/lib/crawler/fetch-robots-txt.js +7 -0
- package/lib/crawler/scan-js-resource-for-license-comment.d.ts +6 -0
- package/lib/crawler/scan-js-resource-for-license-comment.js +6 -0
- package/lib/crawler/types.d.ts +44 -0
- package/lib/crawler-orchestrator.d.ts +6 -0
- package/lib/crawler-orchestrator.js +17 -17
- package/lib/crawler.d.ts +14 -1
- package/lib/crawler.js +23 -0
- package/lib/split-source-transfer-phases.d.ts +11 -0
- package/lib/split-source-transfer-phases.js +18 -0
- package/lib/template-classification/classify-archive-page-templates.d.ts +41 -0
- package/lib/template-classification/classify-archive-page-templates.js +79 -0
- package/lib/template-classification/classify-page-templates.d.ts +37 -0
- package/lib/template-classification/classify-page-templates.js +69 -0
- package/lib/template-classification/collect-page-stylesheet-urls.d.ts +32 -0
- package/lib/template-classification/collect-page-stylesheet-urls.js +130 -0
- package/lib/template-classification/create-content-root-hint.d.ts +36 -0
- package/lib/template-classification/create-content-root-hint.js +47 -0
- package/lib/template-classification/create-page-cluster-factory.d.ts +60 -0
- package/lib/template-classification/create-page-cluster-factory.js +98 -0
- package/lib/template-classification/types.d.ts +108 -0
- package/lib/template-classification/types.js +1 -0
- package/lib/transfer-post-phases.d.ts +10 -0
- package/lib/transfer-post-phases.js +13 -0
- package/lib/utils/object/redact-request-headers.d.ts +15 -0
- package/lib/utils/object/redact-request-headers.js +27 -0
- package/package.json +4 -3
- package/lib/archive/db-ops/analysis/replace-page-templates.js +0 -84
- /package/lib/archive/db-ops/{analysis → templates}/types.js +0 -0
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { Knex } from 'knex';
|
|
2
|
+
/**
|
|
3
|
+
* Copies the four append-only journal tables with fresh (auto-assigned)
|
|
4
|
+
* ids: `list_reconcile_runs`, `network_outages`, `dedupe_cap_events`
|
|
5
|
+
* (none has an FK, so a plain `INSERT ... SELECT` of every non-`id`
|
|
6
|
+
* column suffices — no id remapping needed for these three), and
|
|
7
|
+
* `crawl_errors` (also no FK, but split additionally drops a row whose
|
|
8
|
+
* `url` is no longer present in the output's `url_refs`, so a dropped
|
|
9
|
+
* page's crawl-time errors do not linger in an archive that no longer
|
|
10
|
+
* contains it — concat keeps every `crawl_errors` row unconditionally,
|
|
11
|
+
* since nothing was dropped).
|
|
12
|
+
*
|
|
13
|
+
* `content_items.dedupe_cap_event_id` is deliberately NOT remapped here
|
|
14
|
+
* to point at the copied `dedupe_cap_events` rows — it is always written
|
|
15
|
+
* `NULL` by `insert-content-items.ts`/`replace-content-items.ts` and the
|
|
16
|
+
* mandatory viewer read-model rebuild's `backfillDedupeCapEventId` fully
|
|
17
|
+
* recomputes it afterwards by matching `content_items` rows against
|
|
18
|
+
* `dedupe_cap_events.shape_key` from scratch, so writing a remapped id
|
|
19
|
+
* here would only be immediately overwritten.
|
|
20
|
+
* @param trx - Transaction with the source ATTACHed as
|
|
21
|
+
* {@link TRANSFER_SOURCE_ALIAS}.
|
|
22
|
+
* @param mode - `'split'` filters `crawl_errors` to rows whose `url` (if
|
|
23
|
+
* any) survives in the destination's `url_refs`; `'concat'` copies every
|
|
24
|
+
* row unconditionally.
|
|
25
|
+
* @example
|
|
26
|
+
* ```ts
|
|
27
|
+
* await copyJournalTables(trx, 'split');
|
|
28
|
+
* ```
|
|
29
|
+
*/
|
|
30
|
+
export declare function copyJournalTables(trx: Knex, mode: 'concat' | 'split'): Promise<void>;
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { listTransferColumns } from './list-transfer-columns.js';
|
|
2
|
+
import { quoteTransferIdentifier } from './quote-transfer-identifier.js';
|
|
3
|
+
import { TRANSFER_SOURCE_ALIAS } from './transfer-source-alias.js';
|
|
4
|
+
const SRC = TRANSFER_SOURCE_ALIAS;
|
|
5
|
+
/**
|
|
6
|
+
* Copies the four append-only journal tables with fresh (auto-assigned)
|
|
7
|
+
* ids: `list_reconcile_runs`, `network_outages`, `dedupe_cap_events`
|
|
8
|
+
* (none has an FK, so a plain `INSERT ... SELECT` of every non-`id`
|
|
9
|
+
* column suffices — no id remapping needed for these three), and
|
|
10
|
+
* `crawl_errors` (also no FK, but split additionally drops a row whose
|
|
11
|
+
* `url` is no longer present in the output's `url_refs`, so a dropped
|
|
12
|
+
* page's crawl-time errors do not linger in an archive that no longer
|
|
13
|
+
* contains it — concat keeps every `crawl_errors` row unconditionally,
|
|
14
|
+
* since nothing was dropped).
|
|
15
|
+
*
|
|
16
|
+
* `content_items.dedupe_cap_event_id` is deliberately NOT remapped here
|
|
17
|
+
* to point at the copied `dedupe_cap_events` rows — it is always written
|
|
18
|
+
* `NULL` by `insert-content-items.ts`/`replace-content-items.ts` and the
|
|
19
|
+
* mandatory viewer read-model rebuild's `backfillDedupeCapEventId` fully
|
|
20
|
+
* recomputes it afterwards by matching `content_items` rows against
|
|
21
|
+
* `dedupe_cap_events.shape_key` from scratch, so writing a remapped id
|
|
22
|
+
* here would only be immediately overwritten.
|
|
23
|
+
* @param trx - Transaction with the source ATTACHed as
|
|
24
|
+
* {@link TRANSFER_SOURCE_ALIAS}.
|
|
25
|
+
* @param mode - `'split'` filters `crawl_errors` to rows whose `url` (if
|
|
26
|
+
* any) survives in the destination's `url_refs`; `'concat'` copies every
|
|
27
|
+
* row unconditionally.
|
|
28
|
+
* @example
|
|
29
|
+
* ```ts
|
|
30
|
+
* await copyJournalTables(trx, 'split');
|
|
31
|
+
* ```
|
|
32
|
+
*/
|
|
33
|
+
export async function copyJournalTables(trx, mode) {
|
|
34
|
+
for (const table of ['list_reconcile_runs', 'network_outages', 'dedupe_cap_events']) {
|
|
35
|
+
const columns = await listTransferColumns(trx, SRC, table, ['id']);
|
|
36
|
+
const quoted = columns.map(quoteTransferIdentifier);
|
|
37
|
+
const columnList = quoted.map((col) => `s.${col}`).join(', ');
|
|
38
|
+
await trx.raw(`
|
|
39
|
+
INSERT INTO main.${table} (${quoted.join(', ')})
|
|
40
|
+
SELECT ${columnList} FROM ${SRC}.${table} s
|
|
41
|
+
`);
|
|
42
|
+
}
|
|
43
|
+
const crawlErrorColumns = await listTransferColumns(trx, SRC, 'crawl_errors', ['id']);
|
|
44
|
+
const quotedCrawlErrorColumns = crawlErrorColumns.map(quoteTransferIdentifier);
|
|
45
|
+
const crawlErrorSelectList = quotedCrawlErrorColumns
|
|
46
|
+
.map((col) => `s.${col}`)
|
|
47
|
+
.join(', ');
|
|
48
|
+
const urlSurvivesFilter = mode === 'split'
|
|
49
|
+
? `WHERE s.url IS NULL OR EXISTS (SELECT 1 FROM main.url_refs u WHERE u.url = s.url)`
|
|
50
|
+
: '';
|
|
51
|
+
await trx.raw(`
|
|
52
|
+
INSERT INTO main.crawl_errors (${quotedCrawlErrorColumns.join(', ')})
|
|
53
|
+
SELECT ${crawlErrorSelectList} FROM ${SRC}.crawl_errors s
|
|
54
|
+
${urlSurvivesFilter}
|
|
55
|
+
`);
|
|
56
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { Knex } from 'knex';
|
|
2
|
+
/**
|
|
3
|
+
* Copies `page_console_logs` (one row per page/console-log occurrence)
|
|
4
|
+
* for every `full`/`replace`-action page, remapping `consoleLogId`
|
|
5
|
+
* through `temp.xfer_map_console_log_items`.
|
|
6
|
+
* @param trx - Transaction with the source ATTACHed as
|
|
7
|
+
* {@link TRANSFER_SOURCE_ALIAS}. Must run after
|
|
8
|
+
* `copyDictionariesForConcat`/`copyDictionariesForSplit` has populated
|
|
9
|
+
* `temp.xfer_map_console_log_items`.
|
|
10
|
+
* @example
|
|
11
|
+
* ```ts
|
|
12
|
+
* await copyPageMeta(trx);
|
|
13
|
+
* await copyPageConsoleLogs(trx);
|
|
14
|
+
* ```
|
|
15
|
+
*/
|
|
16
|
+
export declare function copyPageConsoleLogs(trx: Knex): Promise<void>;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { TRANSFER_ACTION } from './transfer-action.js';
|
|
2
|
+
import { TRANSFER_SOURCE_ALIAS } from './transfer-source-alias.js';
|
|
3
|
+
const SRC = TRANSFER_SOURCE_ALIAS;
|
|
4
|
+
/**
|
|
5
|
+
* Copies `page_console_logs` (one row per page/console-log occurrence)
|
|
6
|
+
* for every `full`/`replace`-action page, remapping `consoleLogId`
|
|
7
|
+
* through `temp.xfer_map_console_log_items`.
|
|
8
|
+
* @param trx - Transaction with the source ATTACHed as
|
|
9
|
+
* {@link TRANSFER_SOURCE_ALIAS}. Must run after
|
|
10
|
+
* `copyDictionariesForConcat`/`copyDictionariesForSplit` has populated
|
|
11
|
+
* `temp.xfer_map_console_log_items`.
|
|
12
|
+
* @example
|
|
13
|
+
* ```ts
|
|
14
|
+
* await copyPageMeta(trx);
|
|
15
|
+
* await copyPageConsoleLogs(trx);
|
|
16
|
+
* ```
|
|
17
|
+
*/
|
|
18
|
+
export async function copyPageConsoleLogs(trx) {
|
|
19
|
+
await trx.raw(`
|
|
20
|
+
INSERT INTO main.page_console_logs (pageId, consoleLogId, ts)
|
|
21
|
+
SELECT p.dest_id, m.dest_id, pcl.ts
|
|
22
|
+
FROM ${SRC}.page_console_logs pcl
|
|
23
|
+
JOIN xfer_ci_plan p ON p.src_id = pcl.pageId
|
|
24
|
+
AND p.action IN (${TRANSFER_ACTION.full}, ${TRANSFER_ACTION.replace})
|
|
25
|
+
JOIN xfer_map_console_log_items m ON m.src_id = pcl.consoleLogId
|
|
26
|
+
`);
|
|
27
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import type { Knex } from 'knex';
|
|
2
|
+
/**
|
|
3
|
+
* Copies `page_html_blobs` rows referenced by kept pages' `page_html_ref`.
|
|
4
|
+
*
|
|
5
|
+
* `page_html_blobs.hash` is itself the content-addressed identity (the
|
|
6
|
+
* table's PK, computed the same way in every archive) — unlike every
|
|
7
|
+
* other dictionary in `archive/transfer/`, there is no separate integer id
|
|
8
|
+
* to remap: {@link import('./copy-simple-page-scoped-tables.js').copySimplePageScopedTables}'s
|
|
9
|
+
* `page_html_ref` copy carries the source's `hash` value straight through
|
|
10
|
+
* unchanged, and it already resolves in the destination once this
|
|
11
|
+
* function has run. No `temp.xfer_map_*` table exists for this dictionary.
|
|
12
|
+
*
|
|
13
|
+
* The filter (`action IN (full, replace)`) applies identically to both
|
|
14
|
+
* transfer modes: split's plan never assigns `replace`, so for split this
|
|
15
|
+
* is exactly "full pages only"; concat's plan never assigns `stub`, so for
|
|
16
|
+
* concat this is exactly "every page whose `page_html_ref` copy will
|
|
17
|
+
* actually run" (`stub` rows, split-only, never get a `page_html_ref`
|
|
18
|
+
* copied either way).
|
|
19
|
+
* @param trx - Transaction with the source ATTACHed as
|
|
20
|
+
* {@link TRANSFER_SOURCE_ALIAS}. Must run after `temp.xfer_ci_plan` is
|
|
21
|
+
* fully populated, before `copy-simple-page-scoped-tables.ts`'s `page_html_ref` copy
|
|
22
|
+
* (which assumes the blob it points at already exists — `page_html_ref`
|
|
23
|
+
* has an FK on `hash`).
|
|
24
|
+
* @example
|
|
25
|
+
* ```ts
|
|
26
|
+
* await planContentItemsForSplit(trx);
|
|
27
|
+
* await copyPageHtmlBlobs(trx);
|
|
28
|
+
* await copySimplePageScopedTables(trx); // copies page_html_ref among other tables
|
|
29
|
+
* ```
|
|
30
|
+
*/
|
|
31
|
+
export declare function copyPageHtmlBlobs(trx: Knex): Promise<void>;
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { TRANSFER_ACTION } from './transfer-action.js';
|
|
2
|
+
import { TRANSFER_SOURCE_ALIAS } from './transfer-source-alias.js';
|
|
3
|
+
/**
|
|
4
|
+
* Copies `page_html_blobs` rows referenced by kept pages' `page_html_ref`.
|
|
5
|
+
*
|
|
6
|
+
* `page_html_blobs.hash` is itself the content-addressed identity (the
|
|
7
|
+
* table's PK, computed the same way in every archive) — unlike every
|
|
8
|
+
* other dictionary in `archive/transfer/`, there is no separate integer id
|
|
9
|
+
* to remap: {@link import('./copy-simple-page-scoped-tables.js').copySimplePageScopedTables}'s
|
|
10
|
+
* `page_html_ref` copy carries the source's `hash` value straight through
|
|
11
|
+
* unchanged, and it already resolves in the destination once this
|
|
12
|
+
* function has run. No `temp.xfer_map_*` table exists for this dictionary.
|
|
13
|
+
*
|
|
14
|
+
* The filter (`action IN (full, replace)`) applies identically to both
|
|
15
|
+
* transfer modes: split's plan never assigns `replace`, so for split this
|
|
16
|
+
* is exactly "full pages only"; concat's plan never assigns `stub`, so for
|
|
17
|
+
* concat this is exactly "every page whose `page_html_ref` copy will
|
|
18
|
+
* actually run" (`stub` rows, split-only, never get a `page_html_ref`
|
|
19
|
+
* copied either way).
|
|
20
|
+
* @param trx - Transaction with the source ATTACHed as
|
|
21
|
+
* {@link TRANSFER_SOURCE_ALIAS}. Must run after `temp.xfer_ci_plan` is
|
|
22
|
+
* fully populated, before `copy-simple-page-scoped-tables.ts`'s `page_html_ref` copy
|
|
23
|
+
* (which assumes the blob it points at already exists — `page_html_ref`
|
|
24
|
+
* has an FK on `hash`).
|
|
25
|
+
* @example
|
|
26
|
+
* ```ts
|
|
27
|
+
* await planContentItemsForSplit(trx);
|
|
28
|
+
* await copyPageHtmlBlobs(trx);
|
|
29
|
+
* await copySimplePageScopedTables(trx); // copies page_html_ref among other tables
|
|
30
|
+
* ```
|
|
31
|
+
*/
|
|
32
|
+
export async function copyPageHtmlBlobs(trx) {
|
|
33
|
+
await trx.raw(`
|
|
34
|
+
INSERT INTO main.page_html_blobs (hash, body, codec, size_raw, size_stored)
|
|
35
|
+
SELECT DISTINCT b.hash, b.body, b.codec, b.size_raw, b.size_stored
|
|
36
|
+
FROM ${TRANSFER_SOURCE_ALIAS}.page_html_blobs b
|
|
37
|
+
JOIN ${TRANSFER_SOURCE_ALIAS}.page_html_ref ref ON ref.hash = b.hash
|
|
38
|
+
JOIN xfer_ci_plan p ON p.src_id = ref.page_id
|
|
39
|
+
AND p.action IN (${TRANSFER_ACTION.full}, ${TRANSFER_ACTION.replace})
|
|
40
|
+
WHERE true
|
|
41
|
+
ON CONFLICT(hash) DO NOTHING
|
|
42
|
+
`);
|
|
43
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { Knex } from 'knex';
|
|
2
|
+
/**
|
|
3
|
+
* Copies `page_meta` for every `full`/`replace`-action page (never
|
|
4
|
+
* `stub` — a stub carries no page-scoped data at all, per
|
|
5
|
+
* `transfer-action.ts`'s docs; never `skip`, whose destination row's
|
|
6
|
+
* existing `page_meta` is untouched).
|
|
7
|
+
*
|
|
8
|
+
* `page_meta` has TEN `url_id`-shaped columns and EIGHT `text_id`-shaped
|
|
9
|
+
* columns ({@link PAGE_META_COLUMN_MAPS}), each potentially pointing at a
|
|
10
|
+
* DIFFERENT dictionary row — unlike `content_items`' single `url_id`, one
|
|
11
|
+
* shared join alias cannot serve every column. Each FK column gets its own
|
|
12
|
+
* uniquely-aliased `LEFT JOIN` against the relevant `temp.xfer_map_*`
|
|
13
|
+
* table, built dynamically from {@link listTransferColumns} so a future
|
|
14
|
+
* `page_meta` column addition is picked up without touching this file
|
|
15
|
+
* (only `page-meta-column-maps.ts` needs updating for a new url/text
|
|
16
|
+
* column; a new plain column needs nothing here at all).
|
|
17
|
+
* @param trx - Transaction with the source ATTACHed as
|
|
18
|
+
* {@link TRANSFER_SOURCE_ALIAS}. Must run after every dictionary copy
|
|
19
|
+
* AND after `insert-content-items.ts`/`replace-content-items.ts` have
|
|
20
|
+
* resolved every kept page's `dest_id`.
|
|
21
|
+
* @example
|
|
22
|
+
* ```ts
|
|
23
|
+
* await insertContentItems(trx, { crawlOrderOffset: 0 });
|
|
24
|
+
* await copyPageMeta(trx);
|
|
25
|
+
* ```
|
|
26
|
+
*/
|
|
27
|
+
export declare function copyPageMeta(trx: Knex): Promise<void>;
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { PAGE_META_COLUMN_MAPS } from '../page-meta-column-maps.js';
|
|
2
|
+
import { listTransferColumns } from './list-transfer-columns.js';
|
|
3
|
+
import { quoteTransferIdentifier } from './quote-transfer-identifier.js';
|
|
4
|
+
import { TRANSFER_ACTION } from './transfer-action.js';
|
|
5
|
+
import { TRANSFER_SOURCE_ALIAS } from './transfer-source-alias.js';
|
|
6
|
+
const SRC = TRANSFER_SOURCE_ALIAS;
|
|
7
|
+
const URL_COLUMNS = new Set(PAGE_META_COLUMN_MAPS.url.map((m) => m.target));
|
|
8
|
+
const TEXT_COLUMNS = new Set(PAGE_META_COLUMN_MAPS.text.map((m) => m.target));
|
|
9
|
+
/**
|
|
10
|
+
* Copies `page_meta` for every `full`/`replace`-action page (never
|
|
11
|
+
* `stub` — a stub carries no page-scoped data at all, per
|
|
12
|
+
* `transfer-action.ts`'s docs; never `skip`, whose destination row's
|
|
13
|
+
* existing `page_meta` is untouched).
|
|
14
|
+
*
|
|
15
|
+
* `page_meta` has TEN `url_id`-shaped columns and EIGHT `text_id`-shaped
|
|
16
|
+
* columns ({@link PAGE_META_COLUMN_MAPS}), each potentially pointing at a
|
|
17
|
+
* DIFFERENT dictionary row — unlike `content_items`' single `url_id`, one
|
|
18
|
+
* shared join alias cannot serve every column. Each FK column gets its own
|
|
19
|
+
* uniquely-aliased `LEFT JOIN` against the relevant `temp.xfer_map_*`
|
|
20
|
+
* table, built dynamically from {@link listTransferColumns} so a future
|
|
21
|
+
* `page_meta` column addition is picked up without touching this file
|
|
22
|
+
* (only `page-meta-column-maps.ts` needs updating for a new url/text
|
|
23
|
+
* column; a new plain column needs nothing here at all).
|
|
24
|
+
* @param trx - Transaction with the source ATTACHed as
|
|
25
|
+
* {@link TRANSFER_SOURCE_ALIAS}. Must run after every dictionary copy
|
|
26
|
+
* AND after `insert-content-items.ts`/`replace-content-items.ts` have
|
|
27
|
+
* resolved every kept page's `dest_id`.
|
|
28
|
+
* @example
|
|
29
|
+
* ```ts
|
|
30
|
+
* await insertContentItems(trx, { crawlOrderOffset: 0 });
|
|
31
|
+
* await copyPageMeta(trx);
|
|
32
|
+
* ```
|
|
33
|
+
*/
|
|
34
|
+
export async function copyPageMeta(trx) {
|
|
35
|
+
const columns = await listTransferColumns(trx, SRC, 'page_meta', ['page_id']);
|
|
36
|
+
const joins = [];
|
|
37
|
+
const exprFor = (column) => {
|
|
38
|
+
const quotedColumn = quoteTransferIdentifier(column);
|
|
39
|
+
if (URL_COLUMNS.has(column)) {
|
|
40
|
+
const alias = `mu_${column}`;
|
|
41
|
+
joins.push(`LEFT JOIN xfer_map_url_refs ${alias} ON ${alias}.src_id = pm.${quotedColumn}`);
|
|
42
|
+
return `${alias}.dest_id`;
|
|
43
|
+
}
|
|
44
|
+
if (TEXT_COLUMNS.has(column)) {
|
|
45
|
+
const alias = `mt_${column}`;
|
|
46
|
+
joins.push(`LEFT JOIN xfer_map_text_refs ${alias} ON ${alias}.src_id = pm.${quotedColumn}`);
|
|
47
|
+
return `${alias}.dest_id`;
|
|
48
|
+
}
|
|
49
|
+
if (column === 'meta_extras_json_id') {
|
|
50
|
+
joins.push('LEFT JOIN xfer_map_json_refs mj ON mj.src_id = pm.meta_extras_json_id');
|
|
51
|
+
return 'mj.dest_id';
|
|
52
|
+
}
|
|
53
|
+
return `pm.${quotedColumn}`;
|
|
54
|
+
};
|
|
55
|
+
const selectList = columns.map(exprFor).join(', ');
|
|
56
|
+
const joinList = joins.join('\n');
|
|
57
|
+
const quotedColumnList = columns.map(quoteTransferIdentifier).join(', ');
|
|
58
|
+
await trx.raw(`
|
|
59
|
+
INSERT INTO main.page_meta (page_id, ${quotedColumnList})
|
|
60
|
+
SELECT p.dest_id, ${selectList}
|
|
61
|
+
FROM ${SRC}.page_meta pm
|
|
62
|
+
JOIN xfer_ci_plan p ON p.src_id = pm.page_id
|
|
63
|
+
AND p.action IN (${TRANSFER_ACTION.full}, ${TRANSFER_ACTION.replace})
|
|
64
|
+
${joinList}
|
|
65
|
+
WHERE true
|
|
66
|
+
ON CONFLICT(page_id) DO NOTHING
|
|
67
|
+
`);
|
|
68
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import type { Knex } from 'knex';
|
|
2
|
+
/**
|
|
3
|
+
* Copies `page_template_clusters` rows referenced by at least one kept
|
|
4
|
+
* (`full`/`replace`) page's `page_templates.template_key`, then
|
|
5
|
+
* recomputes `member_count` (and prunes any cluster left with zero
|
|
6
|
+
* members) against the destination's OWN `page_templates` table — which
|
|
7
|
+
* must already reflect this source's copy
|
|
8
|
+
* ({@link import('./copy-simple-page-scoped-tables.js').copySimplePageScopedTables},
|
|
9
|
+
* which carries `page_templates` — see that file's table list).
|
|
10
|
+
*
|
|
11
|
+
* A `template_key` collision between two DIFFERENT sources' clustering
|
|
12
|
+
* runs (concat) is a known, accepted simplification: `template_key` is a
|
|
13
|
+
* blocking-key string from `@d-zero/page-cluster`'s own corpus
|
|
14
|
+
* classification, computed independently per archive, so the same string
|
|
15
|
+
* appearing in two sources does not necessarily mean the same semantic
|
|
16
|
+
* template — `ON CONFLICT(template_key) DO NOTHING` below means the
|
|
17
|
+
* FIRST source's `reason_json` (cluster-selection evidence) wins and the
|
|
18
|
+
* merged `member_count` recompute mixes both sources' pages under it.
|
|
19
|
+
* `concat` therefore re-classifies its output right after this copy,
|
|
20
|
+
* recomputing clean, merged-corpus clusters (see `docs/concat.md`); the
|
|
21
|
+
* copied rows only seed label inheritance for that run.
|
|
22
|
+
* @param trx - Transaction with the source ATTACHed as
|
|
23
|
+
* {@link TRANSFER_SOURCE_ALIAS}. Must run after
|
|
24
|
+
* `copySimplePageScopedTables` (which copies `page_templates` itself).
|
|
25
|
+
* @example
|
|
26
|
+
* ```ts
|
|
27
|
+
* await copySimplePageScopedTables(trx); // copies page_templates
|
|
28
|
+
* await copyPageTemplateClusters(trx);
|
|
29
|
+
* ```
|
|
30
|
+
*/
|
|
31
|
+
export declare function copyPageTemplateClusters(trx: Knex): Promise<void>;
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { TRANSFER_ACTION } from './transfer-action.js';
|
|
2
|
+
import { TRANSFER_SOURCE_ALIAS } from './transfer-source-alias.js';
|
|
3
|
+
const SRC = TRANSFER_SOURCE_ALIAS;
|
|
4
|
+
/**
|
|
5
|
+
* Copies `page_template_clusters` rows referenced by at least one kept
|
|
6
|
+
* (`full`/`replace`) page's `page_templates.template_key`, then
|
|
7
|
+
* recomputes `member_count` (and prunes any cluster left with zero
|
|
8
|
+
* members) against the destination's OWN `page_templates` table — which
|
|
9
|
+
* must already reflect this source's copy
|
|
10
|
+
* ({@link import('./copy-simple-page-scoped-tables.js').copySimplePageScopedTables},
|
|
11
|
+
* which carries `page_templates` — see that file's table list).
|
|
12
|
+
*
|
|
13
|
+
* A `template_key` collision between two DIFFERENT sources' clustering
|
|
14
|
+
* runs (concat) is a known, accepted simplification: `template_key` is a
|
|
15
|
+
* blocking-key string from `@d-zero/page-cluster`'s own corpus
|
|
16
|
+
* classification, computed independently per archive, so the same string
|
|
17
|
+
* appearing in two sources does not necessarily mean the same semantic
|
|
18
|
+
* template — `ON CONFLICT(template_key) DO NOTHING` below means the
|
|
19
|
+
* FIRST source's `reason_json` (cluster-selection evidence) wins and the
|
|
20
|
+
* merged `member_count` recompute mixes both sources' pages under it.
|
|
21
|
+
* `concat` therefore re-classifies its output right after this copy,
|
|
22
|
+
* recomputing clean, merged-corpus clusters (see `docs/concat.md`); the
|
|
23
|
+
* copied rows only seed label inheritance for that run.
|
|
24
|
+
* @param trx - Transaction with the source ATTACHed as
|
|
25
|
+
* {@link TRANSFER_SOURCE_ALIAS}. Must run after
|
|
26
|
+
* `copySimplePageScopedTables` (which copies `page_templates` itself).
|
|
27
|
+
* @example
|
|
28
|
+
* ```ts
|
|
29
|
+
* await copySimplePageScopedTables(trx); // copies page_templates
|
|
30
|
+
* await copyPageTemplateClusters(trx);
|
|
31
|
+
* ```
|
|
32
|
+
*/
|
|
33
|
+
export async function copyPageTemplateClusters(trx) {
|
|
34
|
+
await trx.raw(`
|
|
35
|
+
INSERT INTO main.page_template_clusters
|
|
36
|
+
(template_key, member_count, reason_json, codec, size_raw, size_stored)
|
|
37
|
+
SELECT s.template_key, s.member_count, s.reason_json, s.codec, s.size_raw, s.size_stored
|
|
38
|
+
FROM ${SRC}.page_template_clusters s
|
|
39
|
+
WHERE EXISTS (
|
|
40
|
+
SELECT 1
|
|
41
|
+
FROM ${SRC}.page_templates pt
|
|
42
|
+
JOIN xfer_ci_plan p ON p.src_id = pt.page_id
|
|
43
|
+
AND p.action IN (${TRANSFER_ACTION.full}, ${TRANSFER_ACTION.replace})
|
|
44
|
+
WHERE pt.template_key = s.template_key
|
|
45
|
+
)
|
|
46
|
+
ON CONFLICT(template_key) DO NOTHING
|
|
47
|
+
`);
|
|
48
|
+
await trx.raw(`
|
|
49
|
+
UPDATE main.page_template_clusters
|
|
50
|
+
SET member_count = (
|
|
51
|
+
SELECT COUNT(*) FROM main.page_templates
|
|
52
|
+
WHERE main.page_templates.template_key = main.page_template_clusters.template_key
|
|
53
|
+
)
|
|
54
|
+
`);
|
|
55
|
+
await trx.raw('DELETE FROM main.page_template_clusters WHERE member_count = 0');
|
|
56
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import type { Knex } from 'knex';
|
|
2
|
+
/**
|
|
3
|
+
* Copies `page_template_labels` rows referenced by at least one kept
|
|
4
|
+
* (`full`/`replace`) page's `page_templates.template_key`, prunes any label
|
|
5
|
+
* whose key no longer has a member in the destination's OWN
|
|
6
|
+
* `page_templates`, and then **renumbers label collisions**: two sources
|
|
7
|
+
* (concat) number their labels independently, so both can carry an
|
|
8
|
+
* "events template A" under different keys. Leaving both would give the
|
|
9
|
+
* merged archive two templates with one name — and a later
|
|
10
|
+
* re-classification of the output (`concat` / `split` run one) would *keep* both, since `replacePageTemplates`
|
|
11
|
+
* carries labels forward by member overlap rather than renaming. The later
|
|
12
|
+
* key (by `template_key` order, for determinism) is therefore moved to the
|
|
13
|
+
* next free ordinal in its section here, at copy time.
|
|
14
|
+
*
|
|
15
|
+
* A `template_key` collision (the same key string in both sources) is the
|
|
16
|
+
* same accepted simplification as in
|
|
17
|
+
* {@link import('./copy-page-template-clusters.js').copyPageTemplateClusters}:
|
|
18
|
+
* `ON CONFLICT(template_key) DO NOTHING` keeps the FIRST source's label.
|
|
19
|
+
*
|
|
20
|
+
* A source extracted by an older nitpicker — the tar cache is keyed without
|
|
21
|
+
* a schema version, so an archive first opened before this table existed
|
|
22
|
+
* stays without it until re-extracted — has no `page_template_labels` at
|
|
23
|
+
* all; that source simply contributes no labels rather than failing the
|
|
24
|
+
* whole transfer.
|
|
25
|
+
* @param trx - Transaction with the source ATTACHed as
|
|
26
|
+
* {@link TRANSFER_SOURCE_ALIAS}. Must run after
|
|
27
|
+
* `copySimplePageScopedTables` (which copies `page_templates` itself).
|
|
28
|
+
* @example
|
|
29
|
+
* ```ts
|
|
30
|
+
* await copySimplePageScopedTables(trx); // copies page_templates
|
|
31
|
+
* await copyPageTemplateLabels(trx);
|
|
32
|
+
* ```
|
|
33
|
+
*/
|
|
34
|
+
export declare function copyPageTemplateLabels(trx: Knex): Promise<void>;
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import { TRANSFER_ACTION } from './transfer-action.js';
|
|
2
|
+
import { TRANSFER_SOURCE_ALIAS } from './transfer-source-alias.js';
|
|
3
|
+
const SRC = TRANSFER_SOURCE_ALIAS;
|
|
4
|
+
/**
|
|
5
|
+
* Copies `page_template_labels` rows referenced by at least one kept
|
|
6
|
+
* (`full`/`replace`) page's `page_templates.template_key`, prunes any label
|
|
7
|
+
* whose key no longer has a member in the destination's OWN
|
|
8
|
+
* `page_templates`, and then **renumbers label collisions**: two sources
|
|
9
|
+
* (concat) number their labels independently, so both can carry an
|
|
10
|
+
* "events template A" under different keys. Leaving both would give the
|
|
11
|
+
* merged archive two templates with one name — and a later
|
|
12
|
+
* re-classification of the output (`concat` / `split` run one) would *keep* both, since `replacePageTemplates`
|
|
13
|
+
* carries labels forward by member overlap rather than renaming. The later
|
|
14
|
+
* key (by `template_key` order, for determinism) is therefore moved to the
|
|
15
|
+
* next free ordinal in its section here, at copy time.
|
|
16
|
+
*
|
|
17
|
+
* A `template_key` collision (the same key string in both sources) is the
|
|
18
|
+
* same accepted simplification as in
|
|
19
|
+
* {@link import('./copy-page-template-clusters.js').copyPageTemplateClusters}:
|
|
20
|
+
* `ON CONFLICT(template_key) DO NOTHING` keeps the FIRST source's label.
|
|
21
|
+
*
|
|
22
|
+
* A source extracted by an older nitpicker — the tar cache is keyed without
|
|
23
|
+
* a schema version, so an archive first opened before this table existed
|
|
24
|
+
* stays without it until re-extracted — has no `page_template_labels` at
|
|
25
|
+
* all; that source simply contributes no labels rather than failing the
|
|
26
|
+
* whole transfer.
|
|
27
|
+
* @param trx - Transaction with the source ATTACHed as
|
|
28
|
+
* {@link TRANSFER_SOURCE_ALIAS}. Must run after
|
|
29
|
+
* `copySimplePageScopedTables` (which copies `page_templates` itself).
|
|
30
|
+
* @example
|
|
31
|
+
* ```ts
|
|
32
|
+
* await copySimplePageScopedTables(trx); // copies page_templates
|
|
33
|
+
* await copyPageTemplateLabels(trx);
|
|
34
|
+
* ```
|
|
35
|
+
*/
|
|
36
|
+
export async function copyPageTemplateLabels(trx) {
|
|
37
|
+
const [sourceTable] = (await trx.raw(`SELECT name FROM ${SRC}.sqlite_master WHERE type = 'table' AND name = 'page_template_labels'`));
|
|
38
|
+
if (sourceTable) {
|
|
39
|
+
await trx.raw(`
|
|
40
|
+
INSERT INTO main.page_template_labels (template_key, section, ordinal)
|
|
41
|
+
SELECT s.template_key, s.section, s.ordinal
|
|
42
|
+
FROM ${SRC}.page_template_labels s
|
|
43
|
+
WHERE EXISTS (
|
|
44
|
+
SELECT 1
|
|
45
|
+
FROM ${SRC}.page_templates pt
|
|
46
|
+
JOIN xfer_ci_plan p ON p.src_id = pt.page_id
|
|
47
|
+
AND p.action IN (${TRANSFER_ACTION.full}, ${TRANSFER_ACTION.replace})
|
|
48
|
+
WHERE pt.template_key = s.template_key
|
|
49
|
+
)
|
|
50
|
+
ON CONFLICT(template_key) DO NOTHING
|
|
51
|
+
`);
|
|
52
|
+
}
|
|
53
|
+
await trx.raw(`
|
|
54
|
+
DELETE FROM main.page_template_labels
|
|
55
|
+
WHERE NOT EXISTS (
|
|
56
|
+
SELECT 1 FROM main.page_templates
|
|
57
|
+
WHERE main.page_templates.template_key = main.page_template_labels.template_key
|
|
58
|
+
)
|
|
59
|
+
`);
|
|
60
|
+
await renumberLabelCollisions(trx);
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Gives every `(section, ordinal)` pair held by more than one key a fresh,
|
|
64
|
+
* unused ordinal for all but the first key (by `template_key` order).
|
|
65
|
+
* @param trx - The transfer transaction.
|
|
66
|
+
*/
|
|
67
|
+
async function renumberLabelCollisions(trx) {
|
|
68
|
+
const rows = (await trx('main.page_template_labels')
|
|
69
|
+
.select('template_key as templateKey', 'section', 'ordinal')
|
|
70
|
+
.orderBy('template_key'));
|
|
71
|
+
const maxOrdinalBySection = new Map();
|
|
72
|
+
for (const row of rows) {
|
|
73
|
+
maxOrdinalBySection.set(row.section, Math.max(maxOrdinalBySection.get(row.section) ?? 0, row.ordinal));
|
|
74
|
+
}
|
|
75
|
+
const seen = new Set();
|
|
76
|
+
for (const row of rows) {
|
|
77
|
+
const pair = `${row.section ?? '\0'}:${row.ordinal}`;
|
|
78
|
+
if (!seen.has(pair)) {
|
|
79
|
+
seen.add(pair);
|
|
80
|
+
continue;
|
|
81
|
+
}
|
|
82
|
+
const next = (maxOrdinalBySection.get(row.section) ?? 0) + 1;
|
|
83
|
+
maxOrdinalBySection.set(row.section, next);
|
|
84
|
+
await trx('main.page_template_labels')
|
|
85
|
+
.where('template_key', row.templateKey)
|
|
86
|
+
.update({ ordinal: next });
|
|
87
|
+
}
|
|
88
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { Knex } from 'knex';
|
|
2
|
+
/**
|
|
3
|
+
* Copies `resource_items` (and its `technology_js_scan_cache` companion)
|
|
4
|
+
* for every `full`/`replace`-action row in `temp.xfer_ri_plan`
|
|
5
|
+
* ({@link import('./plan-resource-items.js').planResourceItems}), then
|
|
6
|
+
* backfills each `full` row's `dest_id`.
|
|
7
|
+
*
|
|
8
|
+
* `is_external` is carried over from the source verbatim here — it is
|
|
9
|
+
* NOT authoritative yet. `resource_items.is_external` is a pure scope
|
|
10
|
+
* check (unlike `content_items.is_external`, "was this taken on as a
|
|
11
|
+
* target"), so
|
|
12
|
+
* {@link import('./reclassify-resource-externality.js').reclassifyResourceExternality}
|
|
13
|
+
* always recomputes it against the OUTPUT archive's own (merged or
|
|
14
|
+
* narrowed) scope once every source has been copied — writing the
|
|
15
|
+
* source's value here is only a placeholder that step immediately
|
|
16
|
+
* overwrites.
|
|
17
|
+
* @param trx - Transaction with the source ATTACHed as
|
|
18
|
+
* {@link TRANSFER_SOURCE_ALIAS}. Must run after the dictionary copies
|
|
19
|
+
* (`temp.xfer_map_url_refs`/`xfer_map_blob_refs`/`xfer_map_content_type_refs`/
|
|
20
|
+
* `xfer_map_header_sets` populated) and after
|
|
21
|
+
* {@link import('./plan-resource-items.js').planResourceItems}.
|
|
22
|
+
* @example
|
|
23
|
+
* ```ts
|
|
24
|
+
* await planResourceItems(trx, 'concat');
|
|
25
|
+
* await copyDictionariesForConcat(trx);
|
|
26
|
+
* await copyResourceItems(trx);
|
|
27
|
+
* ```
|
|
28
|
+
*/
|
|
29
|
+
export declare function copyResourceItems(trx: Knex): Promise<void>;
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import { TRANSFER_ACTION } from './transfer-action.js';
|
|
2
|
+
import { TRANSFER_SOURCE_ALIAS } from './transfer-source-alias.js';
|
|
3
|
+
const SRC = TRANSFER_SOURCE_ALIAS;
|
|
4
|
+
/**
|
|
5
|
+
* Copies `resource_items` (and its `technology_js_scan_cache` companion)
|
|
6
|
+
* for every `full`/`replace`-action row in `temp.xfer_ri_plan`
|
|
7
|
+
* ({@link import('./plan-resource-items.js').planResourceItems}), then
|
|
8
|
+
* backfills each `full` row's `dest_id`.
|
|
9
|
+
*
|
|
10
|
+
* `is_external` is carried over from the source verbatim here — it is
|
|
11
|
+
* NOT authoritative yet. `resource_items.is_external` is a pure scope
|
|
12
|
+
* check (unlike `content_items.is_external`, "was this taken on as a
|
|
13
|
+
* target"), so
|
|
14
|
+
* {@link import('./reclassify-resource-externality.js').reclassifyResourceExternality}
|
|
15
|
+
* always recomputes it against the OUTPUT archive's own (merged or
|
|
16
|
+
* narrowed) scope once every source has been copied — writing the
|
|
17
|
+
* source's value here is only a placeholder that step immediately
|
|
18
|
+
* overwrites.
|
|
19
|
+
* @param trx - Transaction with the source ATTACHed as
|
|
20
|
+
* {@link TRANSFER_SOURCE_ALIAS}. Must run after the dictionary copies
|
|
21
|
+
* (`temp.xfer_map_url_refs`/`xfer_map_blob_refs`/`xfer_map_content_type_refs`/
|
|
22
|
+
* `xfer_map_header_sets` populated) and after
|
|
23
|
+
* {@link import('./plan-resource-items.js').planResourceItems}.
|
|
24
|
+
* @example
|
|
25
|
+
* ```ts
|
|
26
|
+
* await planResourceItems(trx, 'concat');
|
|
27
|
+
* await copyDictionariesForConcat(trx);
|
|
28
|
+
* await copyResourceItems(trx);
|
|
29
|
+
* ```
|
|
30
|
+
*/
|
|
31
|
+
export async function copyResourceItems(trx) {
|
|
32
|
+
await trx.raw(`
|
|
33
|
+
INSERT INTO main.resource_items
|
|
34
|
+
(url_id, url_blob_id, is_external, status, status_text, content_type_id, content_length, header_set_id, compress, cdn, source)
|
|
35
|
+
SELECT
|
|
36
|
+
mu.dest_id, mb.dest_id, s.is_external, s.status, s.status_text,
|
|
37
|
+
mct.dest_id, s.content_length, mhs.dest_id, s.compress, s.cdn, s.source
|
|
38
|
+
FROM ${SRC}.resource_items s
|
|
39
|
+
JOIN xfer_ri_plan rp ON rp.src_id = s.id AND rp.action = ${TRANSFER_ACTION.full}
|
|
40
|
+
LEFT JOIN xfer_map_url_refs mu ON mu.src_id = s.url_id
|
|
41
|
+
LEFT JOIN xfer_map_blob_refs mb ON mb.src_id = s.url_blob_id
|
|
42
|
+
LEFT JOIN xfer_map_content_type_refs mct ON mct.src_id = s.content_type_id
|
|
43
|
+
LEFT JOIN xfer_map_header_sets mhs ON mhs.src_id = s.header_set_id
|
|
44
|
+
`);
|
|
45
|
+
await trx.raw(`
|
|
46
|
+
UPDATE xfer_ri_plan
|
|
47
|
+
SET dest_id = x.dest_id
|
|
48
|
+
FROM (
|
|
49
|
+
SELECT rp.src_id AS src_id, d.id AS dest_id
|
|
50
|
+
FROM xfer_ri_plan rp
|
|
51
|
+
JOIN ${SRC}.resource_items s ON s.id = rp.src_id
|
|
52
|
+
LEFT JOIN xfer_map_url_refs mu ON mu.src_id = s.url_id
|
|
53
|
+
LEFT JOIN xfer_map_blob_refs mb ON mb.src_id = s.url_blob_id
|
|
54
|
+
JOIN main.resource_items d ON d.url_id = mu.dest_id OR d.url_blob_id = mb.dest_id
|
|
55
|
+
WHERE rp.action = ${TRANSFER_ACTION.full}
|
|
56
|
+
) x
|
|
57
|
+
WHERE xfer_ri_plan.src_id = x.src_id
|
|
58
|
+
`);
|
|
59
|
+
await trx.raw(`
|
|
60
|
+
UPDATE main.resource_items
|
|
61
|
+
SET
|
|
62
|
+
status = x.status, status_text = x.status_text, content_type_id = x.content_type_id,
|
|
63
|
+
content_length = x.content_length, header_set_id = x.header_set_id,
|
|
64
|
+
compress = x.compress, cdn = x.cdn, source = x.source, is_external = x.is_external
|
|
65
|
+
FROM (
|
|
66
|
+
SELECT
|
|
67
|
+
rp.dest_id AS dest_id, s.status, s.status_text, mct.dest_id AS content_type_id,
|
|
68
|
+
s.content_length, mhs.dest_id AS header_set_id, s.compress, s.cdn, s.source, s.is_external
|
|
69
|
+
FROM xfer_ri_plan rp
|
|
70
|
+
JOIN ${SRC}.resource_items s ON s.id = rp.src_id
|
|
71
|
+
LEFT JOIN xfer_map_content_type_refs mct ON mct.src_id = s.content_type_id
|
|
72
|
+
LEFT JOIN xfer_map_header_sets mhs ON mhs.src_id = s.header_set_id
|
|
73
|
+
WHERE rp.action = ${TRANSFER_ACTION.replace}
|
|
74
|
+
) x
|
|
75
|
+
WHERE main.resource_items.id = x.dest_id
|
|
76
|
+
`);
|
|
77
|
+
await trx.raw(`
|
|
78
|
+
INSERT INTO main.technology_js_scan_cache (resourceId, scannedAt, technology, evidence)
|
|
79
|
+
SELECT rp.dest_id, c.scannedAt, c.technology, c.evidence
|
|
80
|
+
FROM ${SRC}.technology_js_scan_cache c
|
|
81
|
+
JOIN xfer_ri_plan rp ON rp.src_id = c.resourceId
|
|
82
|
+
AND rp.action IN (${TRANSFER_ACTION.full}, ${TRANSFER_ACTION.replace})
|
|
83
|
+
WHERE true
|
|
84
|
+
ON CONFLICT(resourceId) DO UPDATE SET
|
|
85
|
+
scannedAt = excluded.scannedAt,
|
|
86
|
+
technology = excluded.technology,
|
|
87
|
+
evidence = excluded.evidence
|
|
88
|
+
`);
|
|
89
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { Knex } from 'knex';
|
|
2
|
+
/**
|
|
3
|
+
* Copies `resource_ref_edges` (page → resource references) for every
|
|
4
|
+
* `full`/`replace`-action page whose referenced resource is also kept
|
|
5
|
+
* (`temp.xfer_ri_plan`, INNER JOIN — a resource split's
|
|
6
|
+
* `plan-resource-items.ts` dropped has no destination row, so any edge
|
|
7
|
+
* pointing at it is correctly skipped rather than inserted with a
|
|
8
|
+
* dangling `resource_id`).
|
|
9
|
+
* @param trx - Transaction with the source ATTACHed as
|
|
10
|
+
* {@link TRANSFER_SOURCE_ALIAS}. Must run after both
|
|
11
|
+
* `temp.xfer_ci_plan` (with `dest_id` resolved) and `temp.xfer_ri_plan`
|
|
12
|
+
* (with `dest_id` resolved by
|
|
13
|
+
* {@link import('./copy-resource-items.js').copyResourceItems}).
|
|
14
|
+
* @example
|
|
15
|
+
* ```ts
|
|
16
|
+
* await copyResourceItems(trx, 'concat');
|
|
17
|
+
* await copyResourceRefEdges(trx);
|
|
18
|
+
* ```
|
|
19
|
+
*/
|
|
20
|
+
export declare function copyResourceRefEdges(trx: Knex): Promise<void>;
|