Fixing find-by-checksum with exclusions

The NOT-IN query must check for null separately, as everything with
null evaluates to false in sql resulting in not finding existing
duplicates.
This commit is contained in:
Eike Kettner 2021-01-03 12:27:56 +01:00
parent 7b7a8ecd69
commit 95fd386c14

View File

@ -488,7 +488,8 @@ object QItem {
val a = RAttachment.as("a") val a = RAttachment.as("a")
val s = RAttachmentSource.as("s") val s = RAttachmentSource.as("s")
val r = RAttachmentArchive.as("r") val r = RAttachmentArchive.as("r")
val fms = Nel.of(m1, m2, m3)
val qq =
Select( Select(
select(i.all), select(i.all),
from(i) from(i)
@ -500,12 +501,14 @@ object QItem {
.leftJoin(m3, m3.id === r.fileId), .leftJoin(m3, m3.id === r.fileId),
where( where(
i.cid === collective && i.cid === collective &&
(m1.checksum === checksum || m2.checksum === checksum || m3.checksum === checksum) &&? Condition.Or(fms.map(m => m.checksum === checksum)) &&?
Nel Nel
.fromList(excludeFileMeta.toList) .fromList(excludeFileMeta.toList)
.map(excl => m1.id.notIn(excl) && m2.id.notIn(excl) && m3.id.notIn(excl)) .map(excl => Condition.And(fms.map(m => m.id.isNull || m.id.notIn(excl))))
) )
).distinct.build.query[RItem].to[Vector] ).distinct.build
logger.debug(s"FindByChecksum: $qq")
qq.query[RItem].to[Vector]
} }
final case class NameAndNotes( final case class NameAndNotes(