Skip to content

Commit

Permalink
perf(api): move query to cte since it's used twice
Browse files Browse the repository at this point in the history
  • Loading branch information
Maxime Vergez committed Aug 18, 2023
1 parent 7cf26f8 commit 4b5942e
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions backend/geonature/core/gn_synthese/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,14 +85,16 @@ def split_blurring_permissions(permissions):


def build_sensitive_area_filters(query, current_user, sensitive_permissions):
where_clause = query._filter_query_with_permissions(current_user, sensitive_permissions)
sensitive_nomenc = (
nomenclature_cte = (
TNomenclatures.query.with_entities(TNomenclatures.id_nomenclature)
.filter(
TNomenclatures.nomenclature_type.has(BibNomenclaturesTypes.mnemonique == "SENSIBILITE")
)
.filter(TNomenclatures.cd_nomenclature != "0")
.cte("sensible")
)
where_clause = query._filter_query_with_permissions(current_user, sensitive_permissions)
sensitive_nomenc = select(["*"]).select_from(nomenclature_cte)

return sa.and_(
where_clause, query.model.id_nomenclature_sensitivity.in_(sensitive_nomenc)
Expand Down

0 comments on commit 4b5942e

Please sign in to comment.