From e13db0dc43c4479bf0ea9a62f086d36227d56a6e Mon Sep 17 00:00:00 2001 From: Thibault Deckers Date: Thu, 2 Apr 2020 09:32:43 +0900 Subject: [PATCH] debug: clear individual DB tables --- lib/model/favourite_repo.dart | 5 ++++ lib/widgets/debug_page.dart | 51 +++++++++++++++++++++++++++-------- 2 files changed, 45 insertions(+), 11 deletions(-) diff --git a/lib/model/favourite_repo.dart b/lib/model/favourite_repo.dart index 2c21ea9fc..4db0f6f5c 100644 --- a/lib/model/favourite_repo.dart +++ b/lib/model/favourite_repo.dart @@ -28,4 +28,9 @@ class FavouriteRepo { await metadataDb.removeFavourites(removedRows); removedRows.forEach(_rows.remove); } + + Future clear() async { + await metadataDb.clearFavourites(); + _rows.clear(); + } } diff --git a/lib/widgets/debug_page.dart b/lib/widgets/debug_page.dart index 0150ca103..960a00c73 100644 --- a/lib/widgets/debug_page.dart +++ b/lib/widgets/debug_page.dart @@ -64,19 +64,21 @@ class DebugPageState extends State { Text('With GPS: ${withGps.length}'), Text('With address: ${located.length}'), const Divider(), - RaisedButton( - onPressed: () async { - await metadataDb.reset(); - _startDbReport(); - }, - child: const Text('Reset DB'), - ), FutureBuilder( future: _dbFileSizeLoader, builder: (context, AsyncSnapshot snapshot) { if (snapshot.hasError) return Text(snapshot.error.toString()); if (snapshot.connectionState != ConnectionState.done) return const SizedBox.shrink(); - return Text('DB file size: ${formatFilesize(snapshot.data)}'); + return Row( + children: [ + Text('DB file size: ${formatFilesize(snapshot.data)}'), + const Spacer(), + RaisedButton( + onPressed: () => metadataDb.reset().then((_) => _startDbReport()), + child: const Text('Reset DB'), + ), + ], + ); }, ), FutureBuilder( @@ -84,7 +86,16 @@ class DebugPageState extends State { builder: (context, AsyncSnapshot> snapshot) { if (snapshot.hasError) return Text(snapshot.error.toString()); if (snapshot.connectionState != ConnectionState.done) return const SizedBox.shrink(); - return Text('DB metadata rows: ${snapshot.data.length}'); + return Row( + children: [ + Text('DB metadata rows: ${snapshot.data.length}'), + const Spacer(), + RaisedButton( + onPressed: () => metadataDb.clearMetadataEntries().then((_) => _startDbReport()), + child: const Text('Clear'), + ), + ], + ); }, ), FutureBuilder( @@ -92,7 +103,16 @@ class DebugPageState extends State { builder: (context, AsyncSnapshot> snapshot) { if (snapshot.hasError) return Text(snapshot.error.toString()); if (snapshot.connectionState != ConnectionState.done) return const SizedBox.shrink(); - return Text('DB address rows: ${snapshot.data.length}'); + return Row( + children: [ + Text('DB address rows: ${snapshot.data.length}'), + const Spacer(), + RaisedButton( + onPressed: () => metadataDb.clearAddresses().then((_) => _startDbReport()), + child: const Text('Clear'), + ), + ], + ); }, ), FutureBuilder( @@ -100,7 +120,16 @@ class DebugPageState extends State { builder: (context, AsyncSnapshot> snapshot) { if (snapshot.hasError) return Text(snapshot.error.toString()); if (snapshot.connectionState != ConnectionState.done) return const SizedBox.shrink(); - return Text('DB favourite rows: ${snapshot.data.length} (${favourites.count} in memory)'); + return Row( + children: [ + Text('DB favourite rows: ${snapshot.data.length} (${favourites.count} in memory)'), + const Spacer(), + RaisedButton( + onPressed: () => favourites.clear().then((_) => _startDbReport()), + child: const Text('Clear'), + ), + ], + ); }, ), const Divider(),