Skip to content

Commit 896e55d

Browse files
committed
fix: small ones
Signed-off-by: Uroš Marolt <uros@marolt.me>
1 parent ba8b4c2 commit 896e55d

1 file changed

Lines changed: 11 additions & 23 deletions

File tree

services/libs/data-access-layer/src/old/apps/data_sink_worker/repo/requestedForErasureMemberIdentities.repo.ts

Lines changed: 11 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -73,30 +73,22 @@ export default class RequestedForErasureMemberIdentitiesRepository extends Repos
7373
}
7474

7575
if (identity.type === MemberIdentityType.EMAIL) {
76-
// SQL matches case-insensitively (lower(value) = lower(?)), so mirror that here.
77-
// Using find instead of singleOrDefault: case-insensitive matching could produce
78-
// multiple hits if the DB has rows with differing casing for the same email,
79-
// causing singleOrDefault to throw.
76+
// Email is platform-agnostic: the SQL query also omits the platform filter for EMAIL.
77+
// Using find (not singleOrDefault) because case-insensitive matching can return
78+
// multiple rows for the same email stored with different casing.
8079
const row =
8180
data.find(
8281
(r) =>
83-
r.type === identity.type &&
84-
r.value.toLowerCase() === identity.value.toLowerCase() &&
85-
r.platform === identity.platform,
82+
r.type === identity.type && r.value.toLowerCase() === identity.value.toLowerCase(),
8683
) ?? null
8784

88-
if (row) {
89-
results.set(identity, true)
90-
} else {
91-
results.set(identity, false)
92-
}
85+
results.set(identity, row !== null)
9386
} else {
94-
// The SQL query above already filters non-EMAIL identities by platform, so the
95-
// in-memory filter must also include platform. Without it, two identities sharing
96-
// (type, value) but on different platforms would both match. The previous
97-
// singleOrDefault call threw "Array contains more than one matching element!" in that
98-
// case — a deterministic crash that never self-heals.
99-
// SQL matches case-insensitively (lower(value) = lower(?)), so mirror that here.
87+
// The SQL query filters non-EMAIL identities by platform, so the in-memory filter
88+
// must also include platform. Without it, two identities sharing (type, value) but
89+
// on different platforms would both match. The previous singleOrDefault call threw
90+
// "Array contains more than one matching element!" in that case — a deterministic
91+
// crash that never self-heals.
10092
const row =
10193
data.find(
10294
(r) =>
@@ -105,11 +97,7 @@ export default class RequestedForErasureMemberIdentitiesRepository extends Repos
10597
r.platform === identity.platform,
10698
) ?? null
10799

108-
if (row) {
109-
results.set(identity, true)
110-
} else {
111-
results.set(identity, false)
112-
}
100+
results.set(identity, row !== null)
113101
}
114102
}
115103

0 commit comments

Comments
 (0)