mirror of
https://github.com/TheAnachronism/docspell.git
synced 2025-04-05 02:49:32 +00:00
commit
7b7a8ecd69
@ -258,12 +258,12 @@ object OItemSearch {
|
|||||||
store.transact(QAttachment.getAttachmentMeta(id, collective))
|
store.transact(QAttachment.getAttachmentMeta(id, collective))
|
||||||
|
|
||||||
def findByFileCollective(checksum: String, collective: Ident): F[Vector[RItem]] =
|
def findByFileCollective(checksum: String, collective: Ident): F[Vector[RItem]] =
|
||||||
store.transact(QItem.findByChecksum(checksum, collective))
|
store.transact(QItem.findByChecksum(checksum, collective, Set.empty))
|
||||||
|
|
||||||
def findByFileSource(checksum: String, sourceId: Ident): F[Vector[RItem]] =
|
def findByFileSource(checksum: String, sourceId: Ident): F[Vector[RItem]] =
|
||||||
store.transact((for {
|
store.transact((for {
|
||||||
coll <- OptionT(RSource.findCollective(sourceId))
|
coll <- OptionT(RSource.findCollective(sourceId))
|
||||||
items <- OptionT.liftF(QItem.findByChecksum(checksum, coll))
|
items <- OptionT.liftF(QItem.findByChecksum(checksum, coll, Set.empty))
|
||||||
} yield items).getOrElse(Vector.empty))
|
} yield items).getOrElse(Vector.empty))
|
||||||
|
|
||||||
})
|
})
|
||||||
|
@ -63,10 +63,12 @@ object DuplicateCheck {
|
|||||||
|
|
||||||
private def checkDuplicate[F[_]](
|
private def checkDuplicate[F[_]](
|
||||||
ctx: Context[F, Args]
|
ctx: Context[F, Args]
|
||||||
)(fm: FileMeta): ConnectionIO[FileMetaDupes] =
|
)(fm: FileMeta): ConnectionIO[FileMetaDupes] = {
|
||||||
|
val excludes = ctx.args.files.map(_.fileMetaId).toSet
|
||||||
QItem
|
QItem
|
||||||
.findByChecksum(fm.checksum, ctx.args.meta.collective)
|
.findByChecksum(fm.checksum, ctx.args.meta.collective, excludes)
|
||||||
.map(v => FileMetaDupes(fm, v.nonEmpty))
|
.map(v => FileMetaDupes(fm, v.nonEmpty))
|
||||||
|
}
|
||||||
|
|
||||||
case class FileMetaDupes(fm: FileMeta, exists: Boolean)
|
case class FileMetaDupes(fm: FileMeta, exists: Boolean)
|
||||||
}
|
}
|
||||||
|
@ -35,18 +35,20 @@ object ItemHandler {
|
|||||||
analyser: TextAnalyser[F],
|
analyser: TextAnalyser[F],
|
||||||
regexNer: RegexNerFile[F]
|
regexNer: RegexNerFile[F]
|
||||||
): Task[F, Args, Unit] =
|
): Task[F, Args, Unit] =
|
||||||
DuplicateCheck[F]
|
logBeginning.flatMap(_ =>
|
||||||
.flatMap(args =>
|
DuplicateCheck[F]
|
||||||
if (args.files.isEmpty) logNoFiles
|
.flatMap(args =>
|
||||||
else {
|
if (args.files.isEmpty) logNoFiles
|
||||||
val create: Task[F, Args, ItemData] =
|
else {
|
||||||
CreateItem[F].contramap(_ => args.pure[F])
|
val create: Task[F, Args, ItemData] =
|
||||||
create
|
CreateItem[F].contramap(_ => args.pure[F])
|
||||||
.flatMap(itemStateTask(ItemState.Processing))
|
create
|
||||||
.flatMap(safeProcess[F](cfg, itemOps, fts, analyser, regexNer))
|
.flatMap(itemStateTask(ItemState.Processing))
|
||||||
.map(_ => ())
|
.flatMap(safeProcess[F](cfg, itemOps, fts, analyser, regexNer))
|
||||||
}
|
.map(_ => ())
|
||||||
)
|
}
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
def itemStateTask[F[_]: Sync, A](
|
def itemStateTask[F[_]: Sync, A](
|
||||||
state: ItemState
|
state: ItemState
|
||||||
@ -131,11 +133,16 @@ object ItemHandler {
|
|||||||
)
|
)
|
||||||
|
|
||||||
private def logWarn[F[_]](msg: => String): Task[F, Args, Unit] =
|
private def logWarn[F[_]](msg: => String): Task[F, Args, Unit] =
|
||||||
Task(_.logger.warn(msg))
|
Task.log(_.warn(msg))
|
||||||
|
|
||||||
private def logNoFiles[F[_]]: Task[F, Args, Unit] =
|
private def logNoFiles[F[_]]: Task[F, Args, Unit] =
|
||||||
logWarn(
|
logWarn(
|
||||||
"No files to process! Either no files were given or duplicate check removed all."
|
"No files to process! Either no files were given or duplicate check removed all."
|
||||||
)
|
)
|
||||||
|
|
||||||
|
private def logBeginning[F[_]]: Task[F, Args, Unit] =
|
||||||
|
Task { ctx =>
|
||||||
|
val files = ctx.args.files.flatMap(_.name).mkString(", ")
|
||||||
|
ctx.logger.info(s"============ Start processing $files ============")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -454,7 +454,7 @@ object QItem {
|
|||||||
(a.fileId.in(fileMetaIds) ||
|
(a.fileId.in(fileMetaIds) ||
|
||||||
s.fileId.in(fileMetaIds) ||
|
s.fileId.in(fileMetaIds) ||
|
||||||
r.fileId.in(fileMetaIds)) &&? states.map(nel => i.state.in(nel))
|
r.fileId.in(fileMetaIds)) &&? states.map(nel => i.state.in(nel))
|
||||||
)
|
).distinct
|
||||||
}
|
}
|
||||||
|
|
||||||
def findOneByFileIds(fileMetaIds: Seq[Ident]): ConnectionIO[Option[RItem]] =
|
def findOneByFileIds(fileMetaIds: Seq[Ident]): ConnectionIO[Option[RItem]] =
|
||||||
@ -476,7 +476,11 @@ object QItem {
|
|||||||
Vector.empty[RItem].pure[ConnectionIO]
|
Vector.empty[RItem].pure[ConnectionIO]
|
||||||
}
|
}
|
||||||
|
|
||||||
def findByChecksum(checksum: String, collective: Ident): ConnectionIO[Vector[RItem]] = {
|
def findByChecksum(
|
||||||
|
checksum: String,
|
||||||
|
collective: Ident,
|
||||||
|
excludeFileMeta: Set[Ident]
|
||||||
|
): ConnectionIO[Vector[RItem]] = {
|
||||||
val m1 = RFileMeta.as("m1")
|
val m1 = RFileMeta.as("m1")
|
||||||
val m2 = RFileMeta.as("m2")
|
val m2 = RFileMeta.as("m2")
|
||||||
val m3 = RFileMeta.as("m3")
|
val m3 = RFileMeta.as("m3")
|
||||||
@ -496,9 +500,12 @@ 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)
|
(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))
|
||||||
)
|
)
|
||||||
).build.query[RItem].to[Vector]
|
).distinct.build.query[RItem].to[Vector]
|
||||||
}
|
}
|
||||||
|
|
||||||
final case class NameAndNotes(
|
final case class NameAndNotes(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user