diff --git a/backend/gn_module_export/blueprint.py b/backend/gn_module_export/blueprint.py index 6f6dd56..8491d3d 100644 --- a/backend/gn_module_export/blueprint.py +++ b/backend/gn_module_export/blueprint.py @@ -254,7 +254,9 @@ def get_one_export_api(id_export): order by : @TODO """ - limit = request.args.get("limit", default=1000, type=int) + limit = request.args.get( + "limit", default=current_app.config["EXPORTS"]["default_page_size"], type=int + ) offset = request.args.get("offset", default=0, type=int) token = request.args.get("token", default=None, type=str) @@ -273,8 +275,8 @@ def get_one_export_api(id_export): if not export.has_instance_permission(user=user, token=token, scope=scope): raise Forbidden - if limit > 1000: - limit = 1000 + # Capping of the “limit” variable + limit = min(limit, current_app.config["EXPORTS"]["max_page_size"]) args = request.args.to_dict() if "limit" in args: @@ -285,7 +287,7 @@ def get_one_export_api(id_export): args.pop("token") filters = {f: args.get(f) for f in args} - if not "orderby" in filters: + if "orderby" not in filters: filters["orderby"] = export.view_pk_column query = export.get_view_query(limit=limit, offset=offset, filters=filters) @@ -343,7 +345,9 @@ def semantic_dsw(): from .rdf import generate_store_dws - limit = request.args.get("limit", default=1000, type=int) + limit = request.args.get( + "limit", default=current_app.config["EXPORTS"]["default_page_size"], type=int + ) offset = request.args.get("offset", default=0, type=int) args = request.args.to_dict() diff --git a/backend/gn_module_export/conf_schema_toml.py b/backend/gn_module_export/conf_schema_toml.py index e4c5ab4..2115b32 100644 --- a/backend/gn_module_export/conf_schema_toml.py +++ b/backend/gn_module_export/conf_schema_toml.py @@ -21,3 +21,5 @@ class GnModuleSchemaConf(Schema): nb_days_keep_file = fields.Int(load_default=15) csv_separator = fields.String(load_default=";") expose_dsw_api = fields.Boolean(load_default=False) + max_page_size = fields.Int(load_default=1000) + default_page_size = fields.Int(load_default=1000) diff --git a/exports_config.toml.example b/exports_config.toml.example index ed82bd5..13a95dd 100644 --- a/exports_config.toml.example +++ b/exports_config.toml.example @@ -1,6 +1,11 @@ ## Nombre de jours après lequel les fichiers exportés sont supprimés automatiquement sur le serveur nb_days_keep_file = 15 +## Valeurs par défaut et max de la pagination des exports +## Attention, une valeur trop grande peut impacter les performances du serveur +default_page_size = 1000 +max_page_size = 1000 + ## Emplacement des exports, absolus ou relatifs au dossier média de GeoNature export_dsw_dir = 'exports/dsw/' export_dsw_filename = 'export_dsw.ttl'