Self hosted FLOSS fitness/workout, nutrition and weight tracker
Set a maximum limit for pagination sizes
Roland Geider9421e90b04f9
diff --git a/settings/settings_global.py b/settings/settings_global.pyindex 859e4193c..f9f80790f 100644--- a/settings/settings_global.py+++ b/settings/settings_global.py@@ -388,7 +388,7 @@ THUMBNAIL_ALIASES = {#REST_FRAMEWORK = {'DEFAULT_PERMISSION_CLASSES': ('wger.utils.permissions.WgerPermission',),- 'DEFAULT_PAGINATION_CLASS': 'rest_framework.pagination.LimitOffsetPagination',+ 'DEFAULT_PAGINATION_CLASS': 'wger.utils.pagination.WgerLimitOffsetPagination','PAGE_SIZE': 20,'PAGINATE_BY_PARAM': 'limit', # Allow client to override, using `?limit=xxx`.'TEST_REQUEST_DEFAULT_FORMAT': 'json',diff --git a/wger/nutrition/api/views.py b/wger/nutrition/api/views.pyindex 5caebe53b..12f053784 100644--- a/wger/nutrition/api/views.py+++ b/wger/nutrition/api/views.py@@ -70,7 +70,17 @@ class IngredientViewSet(viewsets.ReadOnlyModelViewSet):"""serializer_class = IngredientSerializer- ordering_fields = '__all__'+ # Restrict ordering to indexed columns+ ordering_fields = (+ 'id',+ 'name',+ 'code',+ 'uuid',+ 'remote_id',+ 'last_update',+ 'last_imported',+ 'nutriscore',+ )filterset_class = IngredientFilterSet# Strip default ordering ('name'), this makes the API/DB more performantdiff --git a/wger/utils/pagination.py b/wger/utils/pagination.pyindex a8896f128..0d2d726e7 100644--- a/wger/utils/pagination.py+++ b/wger/utils/pagination.py@@ -14,7 +14,18 @@# along with Workout Manager. If not, see <http://www.gnu.org/licenses/>.# Third Party-from rest_framework.pagination import CursorPagination+from rest_framework.pagination import (+ CursorPagination,+ LimitOffsetPagination,+)+++class WgerLimitOffsetPagination(LimitOffsetPagination):+ """+ Default offset pagination with a hard upper bound on ``limit``.+ """++ max_limit = 999class IngredientCursorPagination(CursorPagination):