mirror of
https://github.com/wger-project/flutter.git
synced 2026-02-19 07:50:52 +01:00
Further reduce the number of requests needed to load the plans sparsely
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user