Skip to content

Commit f796f58

Browse files
committed
small refactor
1 parent ebf6c38 commit f796f58

1 file changed

Lines changed: 11 additions & 26 deletions

File tree

scripts/deduce-category-properties.ts

Lines changed: 11 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -37,18 +37,12 @@ export async function deduce_category_properties(db: Client) {
3737
if (!allowed) continue
3838

3939
await deduce_dual_category_properties(tx, category)
40-
await deduce_satisfied_category_properties(
41-
tx,
42-
category.id,
43-
implications,
44-
true,
45-
)
46-
await deduce_unsatisfied_category_properties(
47-
tx,
48-
category.id,
49-
implications,
50-
true,
51-
)
40+
await deduce_satisfied_category_properties(tx, category.id, implications, {
41+
check_conflicts: false,
42+
})
43+
await deduce_unsatisfied_category_properties(tx, category.id, implications, {
44+
check_conflicts: false,
45+
})
5246
}
5347

5448
await tx.commit()
@@ -141,7 +135,7 @@ async function deduce_satisfied_category_properties(
141135
tx: Transaction,
142136
category_id: string,
143137
implications: NormalizedCategoryImplication[],
144-
ignore_conflicts = false,
138+
options: { check_conflicts: boolean } = { check_conflicts: true },
145139
) {
146140
const satisfied_res = await tx.execute({
147141
sql: `
@@ -194,7 +188,7 @@ async function deduce_satisfied_category_properties(
194188
values.push(category_id, id, reasons[id], i + 1)
195189
}
196190

197-
const insert_sql = !ignore_conflicts
191+
const insert_sql = options.check_conflicts
198192
? `INSERT INTO category_property_assignments
199193
(category_id, property_id, is_satisfied, reason, position, is_deduced)
200194
VALUES ${value_fragments.join(',\n')}`
@@ -215,7 +209,7 @@ async function deduce_unsatisfied_category_properties(
215209
tx: Transaction,
216210
category_id: string,
217211
implications: NormalizedCategoryImplication[],
218-
ignore_conflicts = false,
212+
options: { check_conflicts: boolean } = { check_conflicts: true },
219213
) {
220214
const satisfied_res = await tx.execute({
221215
sql: `
@@ -231,16 +225,7 @@ async function deduce_unsatisfied_category_properties(
231225
)
232226

233227
const unsatisfied_res = await tx.execute({
234-
sql: !ignore_conflicts
235-
? `
236-
SELECT property_id
237-
FROM category_property_assignments
238-
WHERE
239-
category_id = ?
240-
AND is_satisfied = FALSE
241-
AND is_deduced = FALSE
242-
`
243-
: `
228+
sql: `
244229
SELECT property_id
245230
FROM category_property_assignments
246231
WHERE
@@ -307,7 +292,7 @@ async function deduce_unsatisfied_category_properties(
307292
values.push(category_id, id, reasons[id], i + 1)
308293
}
309294

310-
const insert_query = !ignore_conflicts
295+
const insert_query = options.check_conflicts
311296
? `INSERT INTO category_property_assignments
312297
(category_id, property_id, is_satisfied, reason, position, is_deduced)
313298
VALUES ${value_fragments.join(',\n')}`

0 commit comments

Comments
 (0)