Extract find-item query condition

This commit is contained in:
Eike Kettner 2020-12-15 20:16:19 +01:00
parent 2dff686fa0
commit f1c4b4adb0
2 changed files with 39 additions and 40 deletions

View File

@ -170,17 +170,17 @@ object Select {
} }
case class WithCte(cte: CteBind, ctes: Vector[CteBind], query: Select) extends Select { case class WithCte(cte: CteBind, ctes: Vector[CteBind], q: Select) extends Select {
def appendSelect(e: SelectExpr): WithCte = def appendSelect(e: SelectExpr): WithCte =
copy(query = query.appendSelect(e)) copy(q = q.appendSelect(e))
def changeFrom(f: FromExpr => FromExpr): WithCte = def changeFrom(f: FromExpr => FromExpr): WithCte =
copy(query = query.changeFrom(f)) copy(q = q.changeFrom(f))
def changeWhere(f: Condition => Condition): WithCte = def changeWhere(f: Condition => Condition): WithCte =
copy(query = query.changeWhere(f)) copy(q = q.changeWhere(f))
def orderBy(ob: OrderBy, obs: OrderBy*): WithCte = def orderBy(ob: OrderBy, obs: OrderBy*): WithCte =
copy(query = query.orderBy(ob, obs: _*)) copy(q = q.orderBy(ob, obs: _*))
} }
} }

View File

@ -164,7 +164,7 @@ object QItem {
i.cid === q.account.collective, i.cid === q.account.collective,
GroupBy(a.itemId) GroupBy(a.itemId)
), ),
Attachs.aliasName, //alias, todo improve dsl Attachs.aliasName,
Attachs.itemId === i.id Attachs.itemId === i.id
) )
.leftJoin(pers0, pers0.pid === i.corrPerson && pers0.cid === coll) .leftJoin(pers0, pers0.pid === i.corrPerson && pers0.cid === coll)
@ -189,14 +189,8 @@ object QItem {
} }
} }
def findItems( def queryCondition(q: Query): Condition =
q: Query, Condition.unit &&?
maxNoteLen: Int,
batch: Batch
): Stream[ConnectionIO, ListItem] = {
val cond: Condition => Condition =
c =>
c &&?
q.direction.map(d => i.incoming === d) &&? q.direction.map(d => i.incoming === d) &&?
q.name.map(n => i.name.like(QueryWildcard.lower(n))) &&? q.name.map(n => i.name.like(QueryWildcard.lower(n))) &&?
q.allNames q.allNames
@ -227,8 +221,13 @@ object QItem {
.itemsWithEitherTagOrCategory(q.tagsExclude, q.tagCategoryExcl) .itemsWithEitherTagOrCategory(q.tagsExclude, q.tagCategoryExcl)
.map(subsel => i.id.notIn(subsel)) .map(subsel => i.id.notIn(subsel))
def findItems(
q: Query,
maxNoteLen: Int,
batch: Batch
): Stream[ConnectionIO, ListItem] = {
val sql = findItemsBase(q, maxNoteLen) val sql = findItemsBase(q, maxNoteLen)
.changeWhere(cond) .changeWhere(c => c && queryCondition(q))
.limit(batch) .limit(batch)
.build .build
logger.trace(s"List $batch items: $sql") logger.trace(s"List $batch items: $sql")