Skip to content

Commit 71ffdc1

Browse files
committed
fix(V2): reuse cascade issuance lookup for units
1 parent a1b75d8 commit 71ffdc1

1 file changed

Lines changed: 15 additions & 1 deletion

File tree

src/utils/v2-cascade-delete.js

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,16 @@ export const getProjectCascadeUnits = async (projectId, options = {}) => {
219219
return [];
220220
}
221221

222+
return getUnitsForIssuances(issuanceIds, { transaction });
223+
};
224+
225+
const getUnitsForIssuances = async (issuanceIds, options = {}) => {
226+
const { transaction } = options;
227+
228+
if (issuanceIds.length === 0) {
229+
return [];
230+
}
231+
222232
return UnitV2.findAll({
223233
where: { cadTrustIssuanceId: issuanceIds },
224234
raw: true,
@@ -268,7 +278,11 @@ export const stageProjectChildDeletes = async (projectId, options = {}) => {
268278
});
269279
pushRowsForRecords(rows, issuances, 'issuance', 'cad_trust_issuance_id');
270280

271-
const units = await getProjectCascadeUnits(projectId, { transaction });
281+
const issuanceIds = issuances
282+
.map((issuance) => issuance.cadTrustIssuanceId)
283+
.filter(Boolean);
284+
285+
const units = await getUnitsForIssuances(issuanceIds, { transaction });
272286
pushRowsForRecords(rows, units, 'unit', 'cad_trust_unit_id');
273287

274288
const unitIds = units

0 commit comments

Comments
 (0)