mirror of
https://github.com/TheAnachronism/docspell.git
synced 2025-06-21 18:08:25 +00:00
Add a route to return used tags
This is part of the `/insights` route without queries for file usage.
This commit is contained in:
@ -11,7 +11,7 @@ import doobie._
|
||||
import doobie.implicits._
|
||||
|
||||
object QCollective {
|
||||
case class TagCount(id: Ident, name: String, category: Option[String], count: Int)
|
||||
case class TagCount(tag: RTag, count: Int)
|
||||
|
||||
case class InsightData(
|
||||
incoming: Int,
|
||||
@ -22,8 +22,6 @@ object QCollective {
|
||||
|
||||
def getInsights(coll: Ident): ConnectionIO[InsightData] = {
|
||||
val IC = RItem.Columns
|
||||
val TC = RTag.Columns
|
||||
val RC = RTagItem.Columns
|
||||
val q0 = selectCount(
|
||||
IC.id,
|
||||
RItem.table,
|
||||
@ -52,25 +50,33 @@ object QCollective {
|
||||
inner join filemeta m on m.id = a.file_id where a.id in (select aid from attachs)
|
||||
) as t""".query[Option[Long]].unique
|
||||
|
||||
for {
|
||||
n0 <- q0
|
||||
n1 <- q1
|
||||
n2 <- fileSize
|
||||
n3 <- tagCloud(coll)
|
||||
} yield InsightData(n0, n1, n2.getOrElse(0L), n3)
|
||||
}
|
||||
|
||||
def tagCloud(coll: Ident): ConnectionIO[List[TagCount]] = {
|
||||
val TC = RTag.Columns
|
||||
val RC = RTagItem.Columns
|
||||
|
||||
val q3 = fr"SELECT" ++ commas(
|
||||
TC.tid.prefix("t").f,
|
||||
TC.name.prefix("t").f,
|
||||
TC.category.prefix("t").f,
|
||||
fr"count(" ++ RC.itemId.prefix("r").f ++ fr")"
|
||||
TC.all.map(_.prefix("t").f) ++ Seq(fr"count(" ++ RC.itemId.prefix("r").f ++ fr")")
|
||||
) ++
|
||||
fr"FROM" ++ RTagItem.table ++ fr"r" ++
|
||||
fr"INNER JOIN" ++ RTag.table ++ fr"t ON" ++ RC.tagId
|
||||
.prefix("r")
|
||||
.is(TC.tid.prefix("t")) ++
|
||||
fr"WHERE" ++ TC.cid.prefix("t").is(coll) ++
|
||||
fr"GROUP BY" ++ commas(TC.name.prefix("t").f, TC.tid.prefix("t").f, TC.category.prefix("t").f)
|
||||
fr"GROUP BY" ++ commas(
|
||||
TC.name.prefix("t").f,
|
||||
TC.tid.prefix("t").f,
|
||||
TC.category.prefix("t").f
|
||||
)
|
||||
|
||||
for {
|
||||
n0 <- q0
|
||||
n1 <- q1
|
||||
n2 <- fileSize
|
||||
n3 <- q3.query[TagCount].to[List]
|
||||
} yield InsightData(n0, n1, n2.getOrElse(0L), n3)
|
||||
q3.query[TagCount].to[List]
|
||||
}
|
||||
|
||||
def getContacts(
|
||||
|
Reference in New Issue
Block a user