Refactor: replace count() > 0 check with exists() (#24583)

Co-authored-by: Yongtao Huang <99629139+hyongtao-db@users.noreply.github.com>
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
This commit is contained in:
Yongtao Huang
2025-08-27 17:46:52 +08:00
committed by GitHub
parent 34b041e9f0
commit 2a29c61041
7 changed files with 44 additions and 40 deletions

View File

@@ -9,7 +9,7 @@ from collections import Counter
from typing import Any, Literal, Optional
from flask_login import current_user
from sqlalchemy import func, select
from sqlalchemy import exists, func, select
from sqlalchemy.orm import Session
from werkzeug.exceptions import NotFound
@@ -655,10 +655,8 @@ class DatasetService:
@staticmethod
def dataset_use_check(dataset_id) -> bool:
count = db.session.query(AppDatasetJoin).filter_by(dataset_id=dataset_id).count()
if count > 0:
return True
return False
stmt = select(exists().where(AppDatasetJoin.dataset_id == dataset_id))
return db.session.execute(stmt).scalar_one()
@staticmethod
def check_dataset_permission(dataset, user):