From cbdc4a0c561b438f9ef3d1ec43048d1944a69baa Mon Sep 17 00:00:00 2001 From: Roland Geider Date: Mon, 12 Jan 2026 21:56:59 +0100 Subject: [PATCH] Increase page size for languages, no need to use pagination for this Categories and muscles will probably never get so big, but it doesn't do any harm doing it as well. --- lib/providers/exercises.dart | 30 +++++++++++++++---- test/exercises/exercise_provider_db_test.dart | 30 +++++++++++++++++-- test/exercises/exercise_provider_test.dart | 30 +++++++++++++++++-- 3 files changed, 79 insertions(+), 11 deletions(-) diff --git a/lib/providers/exercises.dart b/lib/providers/exercises.dart index 50c8175c..4e87cf16 100644 --- a/lib/providers/exercises.dart +++ b/lib/providers/exercises.dart @@ -1,6 +1,6 @@ /* * This file is part of wger Workout Manager . - * Copyright (C) 2020, 2021 wger Team + * Copyright (c) 2020 - 2026 wger Team * * wger Workout Manager is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by @@ -234,7 +234,12 @@ class ExercisesProvider with ChangeNotifier { Future fetchAndSetCategoriesFromApi() async { _logger.info('Loading exercise categories from API'); - final categories = await baseProvider.fetchPaginated(baseProvider.makeUrl(categoriesUrlPath)); + final categories = await baseProvider.fetchPaginated( + baseProvider.makeUrl( + categoriesUrlPath, + query: {'limit': API_MAX_PAGE_SIZE}, + ), + ); for (final category in categories) { _categories.add(ExerciseCategory.fromJson(category)); } @@ -242,7 +247,12 @@ class ExercisesProvider with ChangeNotifier { Future fetchAndSetMusclesFromApi() async { _logger.info('Loading muscles from API'); - final muscles = await baseProvider.fetchPaginated(baseProvider.makeUrl(musclesUrlPath)); + final muscles = await baseProvider.fetchPaginated( + baseProvider.makeUrl( + musclesUrlPath, + query: {'limit': API_MAX_PAGE_SIZE}, + ), + ); for (final muscle in muscles) { _muscles.add(Muscle.fromJson(muscle)); @@ -251,7 +261,12 @@ class ExercisesProvider with ChangeNotifier { Future fetchAndSetEquipmentsFromApi() async { _logger.info('Loading equipment from API'); - final equipments = await baseProvider.fetchPaginated(baseProvider.makeUrl(equipmentUrlPath)); + final equipments = await baseProvider.fetchPaginated( + baseProvider.makeUrl( + equipmentUrlPath, + query: {'limit': API_MAX_PAGE_SIZE}, + ), + ); for (final equipment in equipments) { _equipment.add(Equipment.fromJson(equipment)); @@ -261,7 +276,12 @@ class ExercisesProvider with ChangeNotifier { Future fetchAndSetLanguagesFromApi() async { _logger.info('Loading languages from API'); - final languageData = await baseProvider.fetchPaginated(baseProvider.makeUrl(languageUrlPath)); + final languageData = await baseProvider.fetchPaginated( + baseProvider.makeUrl( + languageUrlPath, + query: {'limit': API_MAX_PAGE_SIZE}, + ), + ); for (final language in languageData) { _languages.add(Language.fromJson(language)); diff --git a/test/exercises/exercise_provider_db_test.dart b/test/exercises/exercise_provider_db_test.dart index 3862baa6..2d0c1f8b 100644 --- a/test/exercises/exercise_provider_db_test.dart +++ b/test/exercises/exercise_provider_db_test.dart @@ -1,3 +1,21 @@ +/* + * This file is part of wger Workout Manager . + * Copyright (c) 2026 wger Team + * + * wger Workout Manager is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + import 'dart:convert'; import 'package:drift/native.dart'; @@ -100,19 +118,25 @@ void main() { SharedPreferencesAsyncPlatform.instance = InMemorySharedPreferencesAsync.empty(); // Mock categories - when(mockBaseProvider.makeUrl(categoryUrl)).thenReturn(tCategoryEntriesUri); + when( + mockBaseProvider.makeUrl(categoryUrl, query: anyNamed('query')), + ).thenReturn(tCategoryEntriesUri); when( mockBaseProvider.fetchPaginated(tCategoryEntriesUri), ).thenAnswer((_) => Future.value(tCategoryMap['results'])); // Mock muscles - when(mockBaseProvider.makeUrl(muscleUrl)).thenReturn(tMuscleEntriesUri); + when( + mockBaseProvider.makeUrl(muscleUrl, query: anyNamed('query')), + ).thenReturn(tMuscleEntriesUri); when( mockBaseProvider.fetchPaginated(tMuscleEntriesUri), ).thenAnswer((_) => Future.value(tMuscleMap['results'])); // Mock equipment - when(mockBaseProvider.makeUrl(equipmentUrl)).thenReturn(tEquipmentEntriesUri); + when( + mockBaseProvider.makeUrl(equipmentUrl, query: anyNamed('query')), + ).thenReturn(tEquipmentEntriesUri); when( mockBaseProvider.fetchPaginated(tEquipmentEntriesUri), ).thenAnswer((_) => Future.value(tEquipmentMap['results'])); diff --git a/test/exercises/exercise_provider_test.dart b/test/exercises/exercise_provider_test.dart index f0920635..d597759c 100644 --- a/test/exercises/exercise_provider_test.dart +++ b/test/exercises/exercise_provider_test.dart @@ -1,3 +1,21 @@ +/* + * This file is part of wger Workout Manager . + * Copyright (c) 2026 wger Team + * + * wger Workout Manager is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + import 'dart:convert'; import 'package:drift/drift.dart'; @@ -105,19 +123,25 @@ void main() { driftRuntimeOptions.dontWarnAboutMultipleDatabases = true; // Mock categories - when(mockBaseProvider.makeUrl(categoryUrl)).thenReturn(tCategoryEntriesUri); + when( + mockBaseProvider.makeUrl(categoryUrl, query: anyNamed('query')), + ).thenReturn(tCategoryEntriesUri); when( mockBaseProvider.fetchPaginated(tCategoryEntriesUri), ).thenAnswer((_) => Future.value(tCategoryMap['results'])); // Mock muscles - when(mockBaseProvider.makeUrl(muscleUrl)).thenReturn(tMuscleEntriesUri); + when( + mockBaseProvider.makeUrl(muscleUrl, query: anyNamed('query')), + ).thenReturn(tMuscleEntriesUri); when( mockBaseProvider.fetchPaginated(tMuscleEntriesUri), ).thenAnswer((_) => Future.value(tMuscleMap['results'])); // Mock equipment - when(mockBaseProvider.makeUrl(equipmentUrl)).thenReturn(tEquipmentEntriesUri); + when( + mockBaseProvider.makeUrl(equipmentUrl, query: anyNamed('query')), + ).thenReturn(tEquipmentEntriesUri); when( mockBaseProvider.fetchPaginated(tEquipmentEntriesUri), ).thenAnswer((_) => Future.value(tEquipmentMap['results']));