Skip to content

Commit 574239b

Browse files
committed
remove code duplication
1 parent f796f58 commit 574239b

1 file changed

Lines changed: 17 additions & 39 deletions

File tree

scripts/deduce-category-properties.ts

Lines changed: 17 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -131,27 +131,30 @@ async function delete_deduced_category_properties(tx: Transaction, category_id:
131131
})
132132
}
133133

134-
async function deduce_satisfied_category_properties(
134+
async function get_decided_properties(
135135
tx: Transaction,
136136
category_id: string,
137-
implications: NormalizedCategoryImplication[],
138-
options: { check_conflicts: boolean } = { check_conflicts: true },
137+
value: boolean,
139138
) {
140-
const satisfied_res = await tx.execute({
139+
const res = await tx.execute({
141140
sql: `
142141
SELECT property_id
143142
FROM category_property_assignments
144-
WHERE
145-
category_id = ?
146-
AND is_satisfied = TRUE
147-
AND is_deduced = FALSE
143+
WHERE category_id = ? AND is_satisfied = ?
148144
`,
149-
args: [category_id],
145+
args: [category_id, value],
150146
})
151147

152-
const satisfied_props = new Set(
153-
satisfied_res.rows.map((row) => row.property_id) as string[],
154-
) as Set<string>
148+
return new Set(res.rows.map((row) => row.property_id) as string[])
149+
}
150+
151+
async function deduce_satisfied_category_properties(
152+
tx: Transaction,
153+
category_id: string,
154+
implications: NormalizedCategoryImplication[],
155+
options: { check_conflicts: boolean } = { check_conflicts: true },
156+
) {
157+
const satisfied_props = await get_decided_properties(tx, category_id, true)
155158

156159
const deduced_satisfied_props: string[] = []
157160
const reasons: Record<string, string> = {}
@@ -211,33 +214,8 @@ async function deduce_unsatisfied_category_properties(
211214
implications: NormalizedCategoryImplication[],
212215
options: { check_conflicts: boolean } = { check_conflicts: true },
213216
) {
214-
const satisfied_res = await tx.execute({
215-
sql: `
216-
SELECT property_id
217-
FROM category_property_assignments
218-
WHERE category_id = ? AND is_satisfied = TRUE
219-
`,
220-
args: [category_id],
221-
})
222-
223-
const satisfied_props = new Set(
224-
satisfied_res.rows.map((row) => row.property_id) as string[],
225-
)
226-
227-
const unsatisfied_res = await tx.execute({
228-
sql: `
229-
SELECT property_id
230-
FROM category_property_assignments
231-
WHERE
232-
category_id = ?
233-
AND is_satisfied = FALSE
234-
`,
235-
args: [category_id],
236-
})
237-
238-
const unsatisfied_props = new Set(
239-
unsatisfied_res.rows.map((row) => row.property_id) as string[],
240-
)
217+
const satisfied_props = await get_decided_properties(tx, category_id, true)
218+
const unsatisfied_props = await get_decided_properties(tx, category_id, false)
241219

242220
const deduced_unsatisfied_props: string[] = []
243221
const reasons: Record<string, string> = {}

0 commit comments

Comments
 (0)