@tricoteuses/tisseuse 0.14.12 → 0.14.14

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.
@@ -1,6 +1,6 @@
1
- import { n as e, r as t, t as n } from "./resolver-D5TCkLkD.js";
1
+ import { a as e, i as t, o as n, r, t as i } from "./resolver-CuP8arVX.js";
2
2
  //#region src/lib/f_legi/resolver.ts
3
- var r = [
3
+ var a = [
4
4
  "article_location_diffs",
5
5
  "article_num_candidate_stats",
6
6
  "article_num_candidates",
@@ -9,23 +9,26 @@ var r = [
9
9
  "legiarti",
10
10
  "legitext",
11
11
  "scta",
12
- "text_titles_infos"
13
- ], i;
14
- async function a(e) {
12
+ "text_titles_infos",
13
+ "text_titles_infos_parser_cache"
14
+ ], o, s;
15
+ async function c(e) {
15
16
  let t = await e`
16
17
  SELECT required.name
17
- FROM unnest(${e.array([...r])}::text[]) AS required(name)
18
+ FROM unnest(${e.array([...a])}::text[]) AS required(name)
18
19
  WHERE to_regclass(required.name) IS NULL
19
20
  ORDER BY required.name
20
21
  `;
21
22
  if (t.length > 0) throw Error(`The f_legi database is missing required relations: ${t.map(({ name: e }) => e).join(", ")}`);
22
23
  }
23
- var o = class extends n {
24
+ var l = class extends i {
24
25
  flegiDb;
25
26
  articleRowsByNumByTextAndDate = /* @__PURE__ */ new Map();
26
27
  articleNumsLoadedByTextAndDate = /* @__PURE__ */ new Map();
27
28
  articleRowsByContextTextId = /* @__PURE__ */ new Map();
28
29
  directSectionChildrenByParentAndDate = /* @__PURE__ */ new Map();
30
+ directSectionChildrenLoadedRootsAndDate = /* @__PURE__ */ new Set();
31
+ directSectionChildrenRootPromises = /* @__PURE__ */ new Map();
29
32
  globalArticleRowsByNumAndDate = /* @__PURE__ */ new Map();
30
33
  rootTextIdsByTextId = /* @__PURE__ */ new Map();
31
34
  contextTextIdsByTextId = /* @__PURE__ */ new Map();
@@ -39,123 +42,219 @@ var o = class extends n {
39
42
  return t === void 0 ? [] : (await this.getActiveArticleRowsByNum(n, e, t)).get(t) ?? [];
40
43
  }
41
44
  async getDirectSectionChildren({ date: e, parentPath: t }) {
42
- let n = `${t}\0${e}`, r = this.directSectionChildrenByParentAndDate.get(n);
43
- if (r === void 0) {
44
- if (r = await this.getDirectSectionChildrenByExactParentPath({
45
- date: e,
46
- parentPath: t
47
- }), r.length === 0 && !t.includes(".")) {
48
- let n = await this.getRootTextIdsFromTextId(t);
49
- n.length > 1 && (r = await this.flegiDb`
50
- SELECT
51
- dernier_segment AS id,
52
- chemin::text AS path,
53
- titre AS title,
54
- date_debut::text AS "dateDebut",
55
- date_fin::text AS "dateFin"
56
- FROM scta
57
- WHERE
58
- subltree(chemin, 0, 1) = ANY(${this.flegiDb.array(n)}::ltree[])
59
- AND nlevel(chemin) = 2
60
- AND type_objet = 'scta'
61
- AND date_debut <= ${e}::date
62
- AND date_fin >= ${e}::date
63
- ORDER BY tri_hierarchique
64
- `);
45
+ let r = `${t}\0${e}`, i = this.directSectionChildrenByParentAndDate.get(r);
46
+ if (i === void 0) {
47
+ let a = new n("f_legi.getDirectSectionChildren"), o, s = !1;
48
+ if (await a.time("preloadDirectSectionChildrenByRootPath", () => this.preloadDirectSectionChildrenByRootPath(t, e)), i = this.directSectionChildrenByParentAndDate.get(r) ?? [], i.length === 0 && !t.includes(".")) {
49
+ o = await a.time("getRootTextIdsFromTextId", () => this.getRootTextIdsFromTextId(t));
50
+ let n = o;
51
+ n.length > 1 && (s = !0, i = await a.time("queryRootDirectSectionChildren", () => this.flegiDb`
52
+ SELECT
53
+ dernier_segment AS id,
54
+ chemin::text AS path,
55
+ titre AS title,
56
+ date_debut::text AS "dateDebut",
57
+ date_fin::text AS "dateFin"
58
+ FROM scta
59
+ WHERE
60
+ subltree(chemin, 0, 1) = ANY(${this.flegiDb.array(n)}::ltree[])
61
+ AND nlevel(chemin) = 2
62
+ AND type_objet = 'scta'
63
+ AND date_debut <= ${e}::date
64
+ AND date_fin >= ${e}::date
65
+ ORDER BY tri_hierarchique
66
+ `, { count: o.length }));
65
67
  }
66
- this.directSectionChildrenByParentAndDate.set(n, r);
68
+ a.log({
69
+ exactResultCount: o === void 0 ? i.length : 0,
70
+ fallbackResultCount: s ? i.length : void 0,
71
+ fallbackRootTextIdCount: o?.length,
72
+ parentPath: t,
73
+ resultCount: i.length,
74
+ usedFallbackQuery: s
75
+ }), this.directSectionChildrenByParentAndDate.set(r, i);
67
76
  }
68
- return r;
77
+ return i;
69
78
  }
70
79
  async getTextIdFromSegmentId(e) {
71
80
  let t = this.textIdBySegmentId.get(e);
72
81
  return t === void 0 && (t = await this.getTextIdFromSegmentIdUsingContextHeuristic(e) ?? await this.getTextIdFromSegmentIdUsingSctaHeuristic(e) ?? null, this.textIdBySegmentId.set(e, t)), t ?? void 0;
73
82
  }
74
- async preloadTextTitlesInfos(n = {}) {
75
- let r = (e, t = {}) => {
76
- n.onProgress?.({
77
- ...t,
78
- phase: e,
83
+ async preloadTextTitlesInfos(e = {}) {
84
+ let t = (t, n = {}) => {
85
+ e.onProgress?.({
86
+ ...n,
87
+ phase: t,
79
88
  resolver: "f_legi"
80
89
  });
81
- };
82
- if (this.textTitlesInfosLoaded) {
83
- r("already-loaded");
90
+ }, r = new n("f_legi.preloadTextTitlesInfos");
91
+ if (this.schemaValidationPromise ??= c(this.flegiDb).catch((e) => {
92
+ throw this.schemaValidationPromise = void 0, e;
93
+ }), await this.schemaValidationPromise, this.textTitlesInfosLoaded) {
94
+ let e = await this.getTextTitlesInfosParserCacheMeta(r);
95
+ if (e !== void 0 && e.formatVersion === 1 && e.generatedAt === o) {
96
+ t("already-loaded");
97
+ return;
98
+ }
99
+ this.textTitlesInfosLoaded = !1;
100
+ }
101
+ s === void 0 ? s = (async () => await this.loadOrBuildTextTitlesInfosParserCache({
102
+ progress: t,
103
+ timings: r
104
+ }))().catch((e) => {
105
+ throw s = void 0, e;
106
+ }) : t("waiting-for-shared-preload"), o = await s, s = void 0, t("setTextTitlesInfos:done"), r.log(), this.textTitlesInfosLoaded = !0;
107
+ }
108
+ async buildAndCacheTextTitlesInfos({ progress: n, sql: i, timings: a }) {
109
+ await a.time("lockTextTitlesInfos", () => i`SELECT lock_text_titles_infos_for_parser_cache()`), n("queryTextTitlesInfos:start");
110
+ let o = await a.time("queryTextTitlesInfos", () => i`
111
+ SELECT
112
+ cid,
113
+ date_texte::text AS "dateTexte",
114
+ legi_id::text AS id,
115
+ nature,
116
+ num,
117
+ title
118
+ FROM text_titles_infos
119
+ ORDER BY legi_id
120
+ `);
121
+ n("queryTextTitlesInfos:done", { count: o.length }), n("buildTextTitlesInfos:start", { count: o.length });
122
+ let s = performance.now(), c = await r(o, { onProgress: ({ count: e, phase: t }) => n(`buildTextTitlesInfos:${t}`, { count: e }) });
123
+ a.add({
124
+ count: o.length,
125
+ durationMs: Math.round((performance.now() - s) * 10) / 10,
126
+ phase: "buildTextTitlesInfos"
127
+ }), n("buildTextTitlesInfos:done"), n("writeTextTitlesInfosParserCache:start", { count: o.length });
128
+ let [l] = await a.time("writeTextTitlesInfosParserCache", () => i`
129
+ INSERT INTO text_titles_infos_parser_cache (
130
+ key,
131
+ format_version,
132
+ source_row_count,
133
+ generated_at,
134
+ data
135
+ ) VALUES (
136
+ ${e},
137
+ ${1},
138
+ ${o.length},
139
+ now(),
140
+ ${this.flegiDb.json(c)}
141
+ )
142
+ ON CONFLICT (key)
143
+ DO UPDATE SET
144
+ format_version = EXCLUDED.format_version,
145
+ source_row_count = EXCLUDED.source_row_count,
146
+ generated_at = EXCLUDED.generated_at,
147
+ data = EXCLUDED.data
148
+ RETURNING generated_at::text AS "generatedAt"
149
+ `);
150
+ return n("writeTextTitlesInfosParserCache:done", { count: o.length }), t(c), l.generatedAt;
151
+ }
152
+ async getTextTitlesInfosParserCacheMeta(t) {
153
+ let [n] = await t.time("queryTextTitlesInfosParserCacheMeta", () => this.flegiDb`
154
+ SELECT
155
+ format_version AS "formatVersion",
156
+ generated_at::text AS "generatedAt",
157
+ source_row_count AS "sourceRowCount"
158
+ FROM text_titles_infos_parser_cache
159
+ WHERE key = ${e}
160
+ `);
161
+ return n;
162
+ }
163
+ async loadTextTitlesInfosParserCache({ progress: n, sql: r, timings: i }) {
164
+ let a = r ?? this.flegiDb;
165
+ n("queryTextTitlesInfosParserCache:start");
166
+ let [o] = await i.time("queryTextTitlesInfosParserCache", () => a`
167
+ SELECT
168
+ data,
169
+ format_version AS "formatVersion",
170
+ generated_at::text AS "generatedAt",
171
+ source_row_count AS "sourceRowCount"
172
+ FROM text_titles_infos_parser_cache
173
+ WHERE key = ${e}
174
+ `);
175
+ if (o === void 0) {
176
+ n("queryTextTitlesInfosParserCache:miss");
84
177
  return;
85
178
  }
86
- let o = new e("f_legi.preloadTextTitlesInfos");
87
- this.schemaValidationPromise ??= a(this.flegiDb).catch((e) => {
88
- throw this.schemaValidationPromise = void 0, e;
89
- }), await this.schemaValidationPromise, i === void 0 ? (r("queryTextTitlesInfos:start"), i = (async () => {
90
- let e = await o.time("queryTextTitlesInfos", () => this.flegiDb`
91
- SELECT
92
- cid,
93
- date_texte::text AS "dateTexte",
94
- legi_id::text AS id,
95
- nature,
96
- num,
97
- title
98
- FROM text_titles_infos
99
- ORDER BY legi_id
100
- `);
101
- r("queryTextTitlesInfos:done", { count: e.length }), r("buildTextTitlesInfos:start", { count: e.length });
102
- let n = performance.now();
103
- await t(e, { onProgress: ({ count: e, phase: t }) => r(`buildTextTitlesInfos:${t}`, { count: e }) }), o.add({
104
- count: e.length,
105
- durationMs: Math.round((performance.now() - n) * 10) / 10,
106
- phase: "buildTextTitlesInfos"
107
- }), r("buildTextTitlesInfos:done");
108
- })().catch((e) => {
109
- throw i = void 0, e;
110
- })) : r("waiting-for-shared-preload"), await i, r("setTextTitlesInfos:done"), o.log(), this.textTitlesInfosLoaded = !0;
179
+ if (o.formatVersion !== 1) {
180
+ n("queryTextTitlesInfosParserCache:format-mismatch");
181
+ return;
182
+ }
183
+ n("queryTextTitlesInfosParserCache:done", { count: o.sourceRowCount });
184
+ let s = performance.now();
185
+ return t(o.data), i.add({
186
+ count: o.sourceRowCount,
187
+ durationMs: Math.round((performance.now() - s) * 10) / 10,
188
+ phase: "installTextTitlesInfosParserCache"
189
+ }), o.generatedAt;
190
+ }
191
+ async loadOrBuildTextTitlesInfosParserCache({ progress: e, timings: t }) {
192
+ let n = await this.loadTextTitlesInfosParserCache({
193
+ progress: e,
194
+ timings: t
195
+ });
196
+ return n === void 0 ? await this.flegiDb.begin(async (n) => {
197
+ await t.time("waitTextTitlesInfosParserCacheLock", () => n`SELECT pg_advisory_xact_lock(hashtext('text_titles_infos_parser_cache'))`);
198
+ let r = await this.loadTextTitlesInfosParserCache({
199
+ progress: e,
200
+ sql: n,
201
+ timings: t
202
+ });
203
+ return r === void 0 ? await this.buildAndCacheTextTitlesInfos({
204
+ progress: e,
205
+ sql: n,
206
+ timings: t
207
+ }) : r;
208
+ }) : n;
111
209
  }
112
210
  async getUniqueActiveArticlesByNum({ date: e, num: t }) {
113
211
  if (t === void 0) return [];
114
212
  let n = `${t}\0${e}`, r = this.globalArticleRowsByNumAndDate.get(n);
115
213
  return r === void 0 && (r = await this.queryUniqueActiveArticlesByNumsUsingContextHeuristic([t]), this.globalArticleRowsByNumAndDate.set(n, r)), r;
116
214
  }
117
- async preloadUniqueActiveArticlesByNums({ date: t, nums: n }) {
118
- let r = [];
119
- for (let e of n) {
120
- if (e === void 0) continue;
121
- let n = `${e}\0${t}`;
122
- this.globalArticleRowsByNumAndDate.has(n) || r.push(e);
215
+ async preloadUniqueActiveArticlesByNums({ date: e, nums: t }) {
216
+ let r = [], i = /* @__PURE__ */ new Set();
217
+ for (let n of t) {
218
+ if (n === void 0 || i.has(n)) continue;
219
+ i.add(n);
220
+ let t = `${n}\0${e}`;
221
+ this.globalArticleRowsByNumAndDate.has(t) || r.push(n);
123
222
  }
124
223
  if (r.length === 0) return;
125
- let i = new e("f_legi.preloadUniqueActiveArticlesByNums"), a = await i.time("queryGloballyUniqueArticleRowsByNums", () => this.queryGloballyUniqueArticleRowsByNums(r), { count: r.length }), o = new Set(a.map(({ num: e }) => e).filter((e) => e !== null)), s = r.filter((e) => !o.has(e)), c = await i.time("queryUniqueActiveArticlesByNumsUsingContextHeuristic", () => this.queryUniqueActiveArticlesByNumsUsingContextHeuristic(s), { count: s.length }), l = [...a, ...c].toSorted((e, t) => e.id < t.id ? -1 : +(e.id > t.id)), u = /* @__PURE__ */ new Map();
126
- for (let e of r) u.set(e, []);
127
- let d = /* @__PURE__ */ new Map();
128
- for (let e of l) {
224
+ let a = new n("f_legi.preloadUniqueActiveArticlesByNums"), o = await a.time("queryGloballyUniqueArticleRowsByNums", () => this.queryGloballyUniqueArticleRowsByNums(r), { count: r.length }), s = new Set(o.map(({ num: e }) => e).filter((e) => e !== null)), c = r.filter((e) => !s.has(e)), l = await a.time("queryUniqueActiveArticlesByNumsUsingContextHeuristic", () => this.queryUniqueActiveArticlesByNumsUsingContextHeuristic(c), { count: c.length }), u = [...o, ...l].toSorted((e, t) => e.id < t.id ? -1 : +(e.id > t.id)), d = /* @__PURE__ */ new Map();
225
+ for (let e of r) d.set(e, []);
226
+ let f = /* @__PURE__ */ new Map();
227
+ for (let e of u) {
129
228
  if (e.num === null) continue;
130
- let t = d.get(e.num) ?? 0;
131
- d.set(e.num, t + 1), !(t >= 100) && u.get(e.num)?.push(e);
229
+ let t = f.get(e.num) ?? 0;
230
+ f.set(e.num, t + 1), !(t >= 100) && d.get(e.num)?.push(e);
132
231
  }
133
- for (let [e, n] of u) this.globalArticleRowsByNumAndDate.set(`${e}\0${t}`, n);
134
- i.log({
135
- articleRowCount: l.length,
136
- globallyUniqueArticleRowCount: a.length,
137
- heuristicArticleRowCount: c.length,
138
- heuristicNumCount: s.length,
232
+ for (let [t, n] of d) this.globalArticleRowsByNumAndDate.set(`${t}\0${e}`, n);
233
+ a.log({
234
+ articleRowCount: u.length,
235
+ globallyUniqueArticleRowCount: o.length,
236
+ heuristicArticleRowCount: l.length,
237
+ heuristicNumCount: c.length,
139
238
  numCount: r.length
140
239
  });
141
240
  }
142
- async preloadActiveArticlesByTextIds({ date: t, nums: n, textIds: r }) {
143
- let i = n === void 0 ? void 0 : [...new Set(n)].filter(Boolean), a = [...new Set(r)].filter((e) => {
144
- if (e === void 0) return !1;
145
- let n = `${e}\0${t}`;
241
+ async preloadActiveArticlesByTextIds({ date: e, nums: t, textIds: r }) {
242
+ let i = t === void 0 ? void 0 : [...new Set(t)].filter(Boolean), a = [...new Set(r)].filter((t) => {
243
+ if (t === void 0) return !1;
244
+ let n = `${t}\0${e}`;
146
245
  if (this.articleRowsByNumByTextAndDate.get(n) === void 0) return !0;
147
246
  let r = this.articleNumsLoadedByTextAndDate.get(n);
148
247
  return r === "all" ? !1 : i === void 0 ? !0 : i.some((e) => !r?.has(e));
149
248
  });
150
249
  if (a.length === 0) return;
151
- let o = new e("f_legi.preloadActiveArticlesByTextIds"), s = await o.time("getContextTextIdsByTextIds", () => this.getContextTextIdsByTextIds(a)), c = [...new Set([...s.values()].flat())], l = await o.time("getActiveArticleRowsForContextTextIds", () => i === void 0 ? this.getActiveArticleRowsForContextTextIdsWithRoots(c) : this.queryActiveArticleRowsForContextTextIds(c, i), { count: c.length }), u = /* @__PURE__ */ new Map(), d = (e, t) => {
250
+ let o = new n("f_legi.preloadActiveArticlesByTextIds"), s = await o.time("getContextTextIdsByTextIds", () => this.getContextTextIdsByTextIds(a)), c = [...new Set([...s.values()].flat())], l = await o.time("getActiveArticleRowsForContextTextIds", () => i === void 0 ? this.getActiveArticleRowsForContextTextIdsWithRoots(c) : this.queryActiveArticleRowsForContextTextIds(c, i), { count: c.length }), u = /* @__PURE__ */ new Map(), d = (e, t) => {
152
251
  if (e === null) return;
153
252
  let n = u.get(e);
154
253
  n === void 0 ? u.set(e, [t]) : n.push(t);
155
254
  };
156
255
  for (let e of l) d(e.rootTextId, e), d(e.textId, e);
157
- for (let e of a) {
158
- let n = `${e}\0${t}`, r = s.get(e) ?? [e], a = /* @__PURE__ */ new Map();
256
+ for (let t of a) {
257
+ let n = `${t}\0${e}`, r = s.get(t) ?? [t], a = /* @__PURE__ */ new Map();
159
258
  for (let e of r) for (let t of u.get(e) ?? []) a.set(`${t.id}\0${t.textId}`, {
160
259
  id: t.id,
161
260
  textId: t.textId,
@@ -163,11 +262,14 @@ var o = class extends n {
163
262
  dateDebut: t.dateDebut,
164
263
  dateFin: t.dateFin
165
264
  });
166
- let o = this.articleRowsByNumByTextAndDate.get(n) ?? /* @__PURE__ */ new Map();
265
+ let o = this.articleRowsByNumByTextAndDate.get(n) ?? /* @__PURE__ */ new Map(), c = /* @__PURE__ */ new Map();
266
+ for (let [e, t] of o) c.set(e, new Set(t.map((e) => `${e.id}\0${e.textId}`)));
167
267
  for (let e of a.values()) {
168
268
  if (e.num === null) continue;
169
- let t = o.get(e.num);
170
- t === void 0 ? o.set(e.num, [e]) : t.some((t) => t.id === e.id && t.textId === e.textId) || t.push(e);
269
+ let t = `${e.id}\0${e.textId}`, n = c.get(e.num);
270
+ n === void 0 && (n = /* @__PURE__ */ new Set(), c.set(e.num, n));
271
+ let r = o.get(e.num);
272
+ r === void 0 ? (o.set(e.num, [e]), n.add(t)) : n.has(t) || (r.push(e), n.add(t));
171
273
  }
172
274
  if (this.articleRowsByNumByTextAndDate.set(n, o), i === void 0) this.articleNumsLoadedByTextAndDate.set(n, "all");
173
275
  else {
@@ -419,23 +521,40 @@ var o = class extends n {
419
521
  article_rows.order_id
420
522
  `).toSorted((e, t) => e.id.localeCompare(t.id));
421
523
  }
422
- async getDirectSectionChildrenByExactParentPath({ date: e, parentPath: t }) {
423
- return await this.flegiDb`
424
- SELECT
425
- dernier_segment AS id,
426
- chemin::text AS path,
427
- titre AS title,
428
- date_debut::text AS "dateDebut",
429
- date_fin::text AS "dateFin"
430
- FROM scta
431
- WHERE
432
- chemin <@ ${t}::ltree
433
- AND nlevel(chemin) = nlevel(${t}::ltree) + 1
434
- AND type_objet = 'scta'
435
- AND date_debut <= ${e}::date
436
- AND date_fin >= ${e}::date
437
- ORDER BY tri_hierarchique
438
- `;
524
+ async preloadDirectSectionChildrenByRootPath(e, t) {
525
+ let n = e.split(".", 1)[0], r = `${n}\0${t}`;
526
+ if (this.directSectionChildrenLoadedRootsAndDate.has(r)) {
527
+ this.directSectionChildrenByParentAndDate.set(`${e}\0${t}`, this.directSectionChildrenByParentAndDate.get(`${e}\0${t}`) ?? []);
528
+ return;
529
+ }
530
+ let i = this.directSectionChildrenRootPromises.get(r);
531
+ i === void 0 && (i = (async () => {
532
+ let i = /* @__PURE__ */ new Map(), a = await this.flegiDb`
533
+ SELECT
534
+ subltree(chemin, 0, nlevel(chemin) - 1)::text AS "parentPath",
535
+ dernier_segment AS id,
536
+ chemin::text AS path,
537
+ titre AS title,
538
+ date_debut::text AS "dateDebut",
539
+ date_fin::text AS "dateFin"
540
+ FROM scta
541
+ WHERE
542
+ subltree(chemin, 0, 1) = ${n}::ltree
543
+ AND nlevel(chemin) > 1
544
+ AND type_objet = 'scta'
545
+ AND date_debut <= ${t}::date
546
+ AND date_fin >= ${t}::date
547
+ ORDER BY tri_hierarchique
548
+ `;
549
+ for (let { parentPath: e, ...t } of a) {
550
+ let n = i.get(e);
551
+ n === void 0 ? i.set(e, [t]) : n.push(t);
552
+ }
553
+ for (let [e, n] of i) this.directSectionChildrenByParentAndDate.set(`${e}\0${t}`, n);
554
+ this.directSectionChildrenByParentAndDate.set(`${e}\0${t}`, i.get(e) ?? []), this.directSectionChildrenLoadedRootsAndDate.add(r);
555
+ })().finally(() => {
556
+ this.directSectionChildrenRootPromises.delete(r);
557
+ }), this.directSectionChildrenRootPromises.set(r, i)), await i;
439
558
  }
440
559
  async getTextIdFromSegmentIdUsingContextHeuristic(e) {
441
560
  if (e.startsWith("LEGIARTI")) return (await this.flegiDb`
@@ -476,14 +595,14 @@ var o = class extends n {
476
595
  return t === void 0 && (t = (await this.getContextTextIdsByTextIds([e])).get(e) ?? [e], this.contextTextIdsByTextId.set(e, t)), t;
477
596
  }
478
597
  async getContextTextIdsByTextIds(e) {
479
- let t = /* @__PURE__ */ new Map(), n = e.filter((e) => !this.contextTextIdsByTextId.has(e));
598
+ let t = /* @__PURE__ */ new Map(), n = e.filter((e) => !this.contextTextIdsByTextId.has(e)), r = new Set(n);
480
599
  for (let n of e) {
481
600
  let e = this.contextTextIdsByTextId.get(n);
482
601
  e !== void 0 && t.set(n, e);
483
602
  }
484
603
  if (n.length === 0) return t;
485
604
  for (let e of n) t.set(e, [e]);
486
- let r = await this.flegiDb`
605
+ let i = await this.flegiDb`
487
606
  SELECT legi_id AS "textId", cid AS "contextTextId"
488
607
  FROM legitext
489
608
  WHERE legi_id IN ${this.flegiDb(n)} OR cid IN ${this.flegiDb(n)}
@@ -496,10 +615,10 @@ var o = class extends n {
496
615
 
497
616
  ORDER BY "textId", "contextTextId"
498
617
  `;
499
- for (let { contextTextId: e, textId: i } of r) for (let r of [i, e]) {
500
- if (!n.includes(r)) continue;
501
- let i = t.get(r) ?? [r];
502
- i.includes(e) || i.push(e), t.set(r, i);
618
+ for (let { contextTextId: e, textId: n } of i) for (let i of [n, e]) {
619
+ if (!r.has(i)) continue;
620
+ let n = t.get(i) ?? [i];
621
+ n.includes(e) || n.push(e), t.set(i, n);
503
622
  }
504
623
  for (let e of n) this.contextTextIdsByTextId.set(e, t.get(e) ?? [e]);
505
624
  return t;
@@ -509,14 +628,14 @@ var o = class extends n {
509
628
  return t === void 0 && (t = (await this.getRootTextIdsByTextIds([e])).get(e) ?? [e], this.rootTextIdsByTextId.set(e, t)), t;
510
629
  }
511
630
  async getRootTextIdsByTextIds(e) {
512
- let t = /* @__PURE__ */ new Map(), n = e.filter((e) => !this.rootTextIdsByTextId.has(e));
631
+ let t = /* @__PURE__ */ new Map(), n = e.filter((e) => !this.rootTextIdsByTextId.has(e)), r = new Set(n);
513
632
  for (let n of e) {
514
633
  let e = this.rootTextIdsByTextId.get(n);
515
634
  e !== void 0 && t.set(n, e);
516
635
  }
517
636
  if (n.length === 0) return t;
518
637
  for (let e of n) t.set(e, [e]);
519
- let r = await this.flegiDb`
638
+ let i = await this.flegiDb`
520
639
  SELECT cid AS "textId", legi_id AS "rootTextId"
521
640
  FROM legitext
522
641
  WHERE cid IN ${this.flegiDb(n)}
@@ -529,13 +648,14 @@ var o = class extends n {
529
648
 
530
649
  ORDER BY "textId", "rootTextId"
531
650
  `;
532
- for (let { textId: e, rootTextId: n } of r) {
533
- let r = t.get(e) ?? [e];
534
- r.includes(n) || r.push(n), t.set(e, r);
651
+ for (let { textId: e, rootTextId: n } of i) {
652
+ if (!r.has(e)) continue;
653
+ let i = t.get(e) ?? [e];
654
+ i.includes(n) || i.push(n), t.set(e, i);
535
655
  }
536
656
  for (let e of n) this.rootTextIdsByTextId.set(e, t.get(e) ?? [e]);
537
657
  return t;
538
658
  }
539
659
  };
540
660
  //#endregion
541
- export { o as FlegiResolver, a as checkFlegiResolverDatabase };
661
+ export { l as FlegiResolver, c as checkFlegiResolverDatabase };