Skip to content

Commit

Permalink
feat: improve perf route biblistes
Browse files Browse the repository at this point in the history
- Load only necessary fields
- Remove useless parameter id=None
- Fix expression "nb_taxons" in BibListes model

Reviewed-by: andriacap
  • Loading branch information
andriacap committed Nov 21, 2024
1 parent 18b662f commit 5a570e3
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
4 changes: 2 additions & 2 deletions apptax/taxonomie/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -266,8 +266,8 @@ def nb_taxons(self):
@nb_taxons.expression
def nb_taxons(cls):
return (
db.select([db.func.count(cor_nom_liste.id_liste)])
.where(BibListes.id_liste == cls.id_liste)
db.select([db.func.count(cor_nom_liste.c.id_liste)])
.where(cor_nom_liste.c.id_liste == cls.id_liste)
.label("nb_taxons")
)

Expand Down
16 changes: 10 additions & 6 deletions apptax/taxonomie/routesbiblistes.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,21 @@

@adresses.route("/", methods=["GET"])
@json_resp
def get_biblistes(id=None):
def get_biblistes():
"""
retourne les contenu de bib_listes dans "data"
et le nombre d'enregistrements dans "count"
"""
data = db.session.query(BibListes).all()
biblistes_records = db.session.query(
BibListes.id_liste, BibListes.code_liste, BibListes.nom_liste, BibListes.nb_taxons
).all()
biblistes_schema = BibListesSchema()
maliste = {"data": [], "count": 0}
maliste["count"] = len(data)
maliste["data"] = biblistes_schema.dump(data, many=True)
return maliste
biblistes_infos = {
"data": biblistes_schema.dump(biblistes_records, many=True),
"count": len(biblistes_records),
}

return biblistes_infos


@adresses.route("/<regne>", methods=["GET"], defaults={"group2_inpn": None})
Expand Down

0 comments on commit 5a570e3

Please sign in to comment.