Further reduce the number of requests needed to load the plans sparsely

This commit is contained in:
Roland Geider
2021-05-13 13:56:16 +02:00
parent 2468e600c6
commit eb3214ab2f
2 changed files with 15 additions and 7 deletions

View File

@@ -84,10 +84,13 @@ class NutritionPlansProvider extends WgerBaseProvider with ChangeNotifier {
/// Fetches and sets all plans sparsely, i.e. only with the data on the plan
/// object itself and no child attributes
Future<void> fetchAndSetAllPlansSparse() async {
final data = await fetch(makeUrl(_nutritionalPlansPath));
for (final entry in data['results']) {
await fetchAndSetPlanSparse(entry['id']);
final data = await fetch(makeUrl(_nutritionalPlansPath, query: {'limit': '1000'}));
for (final planData in data['results']) {
final plan = NutritionalPlan.fromJson(planData);
_plans.add(plan);
_plans.sort((a, b) => b.creationDate.compareTo(a.creationDate));
}
notifyListeners();
}
/// Fetches and sets all plans fully, i.e. with all corresponding child objects

View File

@@ -127,7 +127,10 @@ class WorkoutPlansProvider extends WgerBaseProvider with ChangeNotifier {
/// Fetches and sets all workout plans fully, i.e. with all corresponding child
/// attributes
Future<void> fetchAndSetAllPlansFull() async {
final data = await fetch(makeUrl(_workoutPlansUrlPath, query: {'ordering': '-creation_date'}));
final data = await fetch(makeUrl(
_workoutPlansUrlPath,
query: {'ordering': '-creation_date', 'limit': '1000'},
));
for (final entry in data['results']) {
await fetchAndSetWorkoutPlanFull(entry['id']);
}
@@ -138,9 +141,11 @@ class WorkoutPlansProvider extends WgerBaseProvider with ChangeNotifier {
/// Fetches all workout plan sparsely, i.e. only with the data on the plan
/// object itself and no child attributes
Future<void> fetchAndSetAllPlansSparse() async {
final data = await fetch(makeUrl(_workoutPlansUrlPath, query: {'ordering': '-creation_date'}));
for (final entry in data['results']) {
await fetchAndSetPlanSparse(entry['id']);
final data = await fetch(makeUrl(_workoutPlansUrlPath, query: {'limit': '1000'}));
for (final workoutPlanData in data['results']) {
final plan = WorkoutPlan.fromJson(workoutPlanData);
_workoutPlans.add(plan);
_workoutPlans.sort((a, b) => b.creationDate.compareTo(a.creationDate));
}
notifyListeners();