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

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