mirror of
https://github.com/wger-project/flutter.git
synced 2026-02-18 00:17:48 +01:00
Workaround for duplicate exercises in the DB
This commit is contained in:
@@ -295,14 +295,20 @@ class ExercisesProvider with ChangeNotifier {
|
||||
ExerciseDatabase database,
|
||||
int exerciseId,
|
||||
) async {
|
||||
// if (exerciseId == 76) {
|
||||
// print('76!!!!');
|
||||
// }
|
||||
|
||||
Exercise exercise;
|
||||
final exerciseDb = await (database.select(database.exercises)
|
||||
..where((e) => e.id.equals(exerciseId)))
|
||||
.getSingleOrNull();
|
||||
|
||||
// TODO: this should be a .getSingleOrNull()!!! However, for some reason there
|
||||
// are duplicates in the db. Perhaps a race condition so that two
|
||||
// entries are written at the same time or something?
|
||||
var exerciseResult =
|
||||
await (database.select(database.exercises)..where((e) => e.id.equals(exerciseId))).get();
|
||||
|
||||
ExerciseTable? exerciseDb;
|
||||
if (exerciseResult.length > 0) {
|
||||
exerciseDb = exerciseResult.first;
|
||||
} else {
|
||||
exerciseDb = null;
|
||||
}
|
||||
|
||||
// Exercise is already known locally
|
||||
if (exerciseDb != null) {
|
||||
|
||||
@@ -173,13 +173,13 @@ class RoutinesProvider with ChangeNotifier {
|
||||
for (final setConfig in slot.setConfigs) {
|
||||
setConfig.exercise = (await _exercises.fetchAndSetExercise(setConfig.exerciseId))!;
|
||||
|
||||
// setConfig.repsUnit = _repetitionUnit.firstWhere(
|
||||
// (e) => e.id == setConfig.repsUnitId,
|
||||
// );
|
||||
//
|
||||
// setConfig.weightUnit = _weightUnits.firstWhere(
|
||||
// (e) => e.id == setConfig.weightUnitId,
|
||||
// );
|
||||
setConfig.repsUnit = _repetitionUnit.firstWhere(
|
||||
(e) => e.id == setConfig.repsUnitId,
|
||||
);
|
||||
|
||||
setConfig.weightUnit = _weightUnits.firstWhere(
|
||||
(e) => e.id == setConfig.weightUnitId,
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -231,18 +231,20 @@ class RoutinesProvider with ChangeNotifier {
|
||||
objectMethod: _routinesCurrentIterationGymSubpath,
|
||||
),
|
||||
),
|
||||
baseProvider.fetchPaginated(baseProvider.makeUrl(
|
||||
_logsUrlPath,
|
||||
query: {'workout': routineId.toString(), 'limit': '900'},
|
||||
))
|
||||
baseProvider.fetchPaginated(
|
||||
baseProvider.makeUrl(
|
||||
_logsUrlPath,
|
||||
query: {'routine': routineId.toString(), 'limit': '900'},
|
||||
),
|
||||
),
|
||||
]);
|
||||
|
||||
final routine = Routine.fromJson(results[0] as Map<String, dynamic>);
|
||||
|
||||
final dayData = results[1] as List<dynamic>;
|
||||
final currentIterationDisplayData = results[2] as List<dynamic>;
|
||||
final currentIterationGymData = results[2] as List<dynamic>;
|
||||
final logData = results[3] as List<dynamic>;
|
||||
final currentIterationGymData = results[3] as List<dynamic>;
|
||||
final logData = results[4] as List<dynamic>;
|
||||
|
||||
/*
|
||||
* Set exercise, repetition and weight unit objects
|
||||
@@ -279,10 +281,6 @@ class RoutinesProvider with ChangeNotifier {
|
||||
// Logs
|
||||
routine.logs = [];
|
||||
|
||||
// final logData = await baseProvider.fetchPaginated(baseProvider.makeUrl(
|
||||
// _logsUrlPath,
|
||||
// query: {'workout': routineId.toString(), 'limit': '900'},
|
||||
// ));
|
||||
for (final logEntry in logData) {
|
||||
try {
|
||||
final log = Log.fromJson(logEntry);
|
||||
|
||||
Reference in New Issue
Block a user