🎨 — Modify count_tasks behavior, improve its signature

This commit is contained in:
Luc Didry 2024-05-27 10:54:08 +02:00
parent 7bfe676b5c
commit be492ed2ee
No known key found for this signature in database
GPG key ID: EA868E12D0257E3C
2 changed files with 8 additions and 7 deletions

View file

@ -51,7 +51,7 @@ def create_start_app_handler(appli):
db = await connect_to_db(appli)
tasks_count = await queries.count_tasks(db, all_tasks=True)
tasks_count = await queries.count_tasks(db)
if tasks_count == 0:
logger.warning(
"There is no tasks in the database. "

View file

@ -1,7 +1,7 @@
"""Functions to ease SQL queries management"""
from datetime import datetime, timedelta
from hashlib import sha256
from typing import List
from typing import List, Union
from urllib.parse import urljoin
from sqlalchemy import desc, func
@ -48,11 +48,12 @@ async def create_result(db: Session, agent_result: schemas.AgentResult, agent_id
return result
async def count_tasks(db: Session, selected=False, all_tasks=False):
async def count_tasks(db: Session, selected: Union[None, bool] = None):
query = db.query(Task)
if selected is not None:
if selected:
query = query.filter(Task.selected_by is not None)
elif not all_tasks:
else:
query = query.filter(Task.selected_by is None)
return query.count()