Skip to content

Commit

Permalink
[fix] Customizable limit page size (cf. PnX-SI#198)
Browse files Browse the repository at this point in the history
  • Loading branch information
hypsug0 committed Aug 20, 2024
1 parent e22ed1b commit 48b8c30
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 5 deletions.
14 changes: 9 additions & 5 deletions backend/gn_module_export/blueprint.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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:
Expand All @@ -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)
Expand Down Expand Up @@ -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()
Expand Down
2 changes: 2 additions & 0 deletions backend/gn_module_export/conf_schema_toml.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
5 changes: 5 additions & 0 deletions exports_config.toml.example
Original file line number Diff line number Diff line change
@@ -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'
Expand Down

0 comments on commit 48b8c30

Please sign in to comment.